Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
PHP Datepicker Validate if age is lower than 18 years old

Can I do a warning validate from Datepicker and alert swal like this?

I do that and it error that is_string is not defined.

I'm new in php btw

The comment is a think that i tried to make in different way sorry abort that.

form

<div class="form-group">
<label>Birthdate</label>
    <div class="input-group date">
    <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" class="form-control datepicker_class" id="birth_date" name="birth_date" onchange="validateAge">
    </div>
</div>

function

function validateAge(){
var birthday = new $('#birth_date').val();
// let birthday = $('#birth_date').val();

// check = explode('/',birthday);
birthday = explode("/", birthday);
// alert(check);

if (is_string(birthday)) {
    birthday = strtotime(birthday);
}

// check
// 31536000 is the number of seconds in a 365 days year. strtotime for 1 years : 31556926 
if(time() - birthday < 18 * 31556926)  {
    swal({
            title: "warning",
            text: "your age is lower than 18",
            type: "warning"
        });
}

return true;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In javascript there is no is_string() function. To check if variable is string you can do it this way:

if (typeof birthday === 'string' || birthday instanceof String) 
//string
else
//not string
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!