date validation with regex

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

date validation with regex

Postby srowe » Fri Jul 31, 2009 10:58 pm

I am using a regex expression to validate that the date has a 4 digit year.

I am passing a string to this function and it is not working correctly.

Can someone help me with this?

When I pass 07/29/80 it returns false;
when I pass 07/29/1980 it returns false;



function isDate()
{
var dt = arguments[0];
var dateExpression = '^\d{2}\/\d{2}\/\d{4}$';
var dtval = dt.match(dateExpression);
if(!dtval){
return false;
}else{
return true;
}
}
srowe
 
Posts: 74
Joined: Wed May 02, 2007 3:01 pm
Location: USA Missouri

Re: date validation with regex

Postby agiletortoise » Sat Aug 01, 2009 12:15 am

You declared your dateExpression as a string, not a regular expression, try...

Code: Select all
var dateExpression = /^\d{2}\/\d{2}\/\d{4}$/;
User avatar
agiletortoise
 
Posts: 278
Joined: Wed Oct 12, 2005 3:26 pm
Location: Texas, USA

Re: date validation with regex

Postby srowe » Mon Aug 03, 2009 3:49 pm

Perfect!


Thank you.
srowe
 
Posts: 74
Joined: Wed May 02, 2007 3:01 pm
Location: USA Missouri


Return to Web Development

Who is online

Users browsing this forum: No registered users and 9 guests

cron