Return to Snippet

Revision: 54817
at January 13, 2012 01:54 by steppannws


Initial Code
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 "";
}

Initial URL

                                

Initial Description
Validate Birth day.

Initial Title
Birth date validation

Initial Tags
date

Initial Language
ActionScript 3