Comprobar fecha


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**--------------------------
  2. //* Validate Date Field script- By JavaScriptKit.com
  3. //* For this script and 100s more, visit http://www.javascriptkit.com
  4. //* This notice must stay intact for usage
  5. ---------------------------**/
  6.  
  7. /*
  8.  * Retocado por Sendoa Portuondo para un funcionamiento más personalizado
  9.  */
  10. function checkdate(dia, mes, anio){
  11. var validformat = /^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
  12. var returnval = false;
  13.  
  14. if(!validformat.test(input.value)){
  15. return false;
  16. }else{ //Detailed check for valid date ranges
  17. var monthfield = mes;
  18. var dayfield = dia;
  19. var yearfield = anio;
  20. var dayobj = new Date(yearfield, monthfield-1, dayfield);
  21. if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)){
  22. return false;
  23. }else{
  24. return true;
  25. }
  26. }
  27.  
  28. return true;
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.