View Full Version : Regular Expression

01-14-2004, 01:11 PM
I have a bit of Javascript that is checking to see that a date is enter in this format DD/MM/YYYY
sDate is the input field

if(isNaN(sDate.substring(0, 2)) || isNaN(sDate.substring(3, 5)) || isNaN(sDate.substring(6, 10)) || sDate.charAt(2) != "/" || sDate.charAt(5) != "/") {
alert("Date needs to be in format DD/MM/YYYY.");
return false;

Problem is I have been told that it must accept say 1/9/2004 which the above doesn't accept.

Im rubbish at Regular Expressions, is there a regular expression that can do this check?

TIA Dale

01-14-2004, 02:34 PM
I had a similar topic not that long ago, anyhow, you can find if you try the lovely search engine.

But since I am such a nice guy I'll provide the link to it ;)

liorean gave me an example and a very detailed explanation of how it works. It was extremely useful to me on my way of understanding regExp's and hopefully it will be just as useful to you too!

RegExp - validate date