/ Published in: ActionScript 3
Validate Birth day.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private function checkDate(s:String):String { if (s.search(/^\d{1,2}[\/|\-|\.|_]\d{1,2}[\/|\-|\.|_]\d{4}/g) != 0) return "error"; var temp:Array = s.split("/"); s = temp[1] + "/" + temp[0] + "/" + temp[2]; s = s.replace(/[\-|\.|_]/g, "/"); var dt:Date = new Date(Date.parse(s)); var now:Date = new Date(); var arrDateParts:Array = s.split("/"); if (dt.getMonth() == arrDateParts[0]-1 && dt.getDate() == arrDateParts[1] && dt.getFullYear() == arrDateParts[2]) { if((now.getFullYear()-arrDateParts[2]) >= 18) return "ok"; else return "minor"; } else { return "invalid format"; } return ""; }