Birth date validation


/ Published in: ActionScript 3
Save to your folder(s)

Validate Birth day.


Copy this code and paste it in your HTML
  1. private function checkDate(s:String):String
  2. {
  3. if (s.search(/^\d{1,2}[\/|\-|\.|_]\d{1,2}[\/|\-|\.|_]\d{4}/g) != 0)
  4. return "error";
  5.  
  6. var temp:Array = s.split("/");
  7. s = temp[1] + "/" + temp[0] + "/" + temp[2];
  8.  
  9. s = s.replace(/[\-|\.|_]/g, "/");
  10.  
  11. var dt:Date = new Date(Date.parse(s));
  12. var now:Date = new Date();
  13.  
  14. var arrDateParts:Array = s.split("/");
  15.  
  16. if (dt.getMonth() == arrDateParts[0]-1 && dt.getDate() == arrDateParts[1] && dt.getFullYear() == arrDateParts[2])
  17. {
  18. if((now.getFullYear()-arrDateParts[2]) >= 18)
  19. return "ok";
  20. else
  21. return "minor";
  22. }
  23. else
  24. {
  25. return "invalid format";
  26. }
  27.  
  28. return "";
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.