Skip to content

Instantly share code, notes, and snippets.

@YurePereira
Created July 6, 2016 13:53
Show Gist options
  • Select an option

  • Save YurePereira/9dbcb5e19dcc348b15cfabe67ec5d090 to your computer and use it in GitHub Desktop.

Select an option

Save YurePereira/9dbcb5e19dcc348b15cfabe67ec5d090 to your computer and use it in GitHub Desktop.
/**
* Função que faz a validação de DATA verificando se ela está no formato mm/dd/aaaa, assim retornando TRUE caso esteja
* e FALSE caso contrario.
*/
function validateDateBrazil(c) {
if (c.match(/^[0-9]{1,2}\/[0-9]{1,2}\/[1-9]{1}[0-9]{3}$/)){
var day = c.replace(/([0-9]{1,2})\/[0-9]{1,2}\/[0-9]{4}/,'$1'),
month = c.replace(/[0-9]{1,2}\/([0-9]{1,2})\/[0-9]{4}/,'$1'),
year = c.replace(/[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{4})/,'$1');
return ((day >= 1 && day <= 31) && (month >= 1 && month <= 12) && (year > 0)) ? true : false;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment