Jump to content

VALIDATION !


tuxedo210
 Share

Recommended Posts

I wrote my own little version as I thought that website one was a little long, and hadn't done one before. Let me know what you think:

<script type='text/javascript'>/*Date ParserCreated for W3Schools by Blue*/var iDate = "31/01/1962";function check_day_month(mon,year){	var myRegMon = new RegExp("(04||06||09||11)");		if(myRegMon.exec( mon ) && RegExp.$1 != ""){  return '30';	} else if(mon == '02'){  return check_feb(year);	} else {  return '31';	}}function check_feb(yr){	if( (yr / 4) == Math.floor(yr / 4) ){  return '29';	} else {  return '28';	}}function check_date(theDate){	var myRegEx = new RegExp(/\d{2}\/\d{2}\/\d{4}/);		if(theDate.length != 10 || myRegEx.test(theDate) == false){  return 'The field must be in the correct format';	}	var iSplit = theDate.split(/\//g);	iSplit[2] = Math.floor(iSplit[2]);	if( Math.floor(iSplit[0]) > check_day_month( iSplit[1] , iSplit[2] ) ){  return 'The number of days set was not correct for the month/year';  	}		return 'The date was parsed successfully';}var myResult = check_date(iDate);document.write(myResult);</script>

:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...