Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda