Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda