: Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))(\/|-|\.)(? var value = " "; // capture all the parts var matches = value.match(/^(\d)\.(\d)\.(\d) (\d):(\d):(\d)$/); //alt: // value.match(/^(\d).(\d).(\d).(\d).(\d).(\d)$/); // also matches 22/05/2013 and 22a0592013,[email protected] if (matches === null) else You need to properly test the regular expression to make sure it matches the date format you want. Alternatively since you are already using j Query, you could try using a validation plugin such as It does not check for leap years or invalid dates at the end of short months.As we've seen before, creating re-usable functions can significantly reduce the size of your Java Script code.The year limitation would be used if you were asking for a date of birth or date of some recent event.If you're setting up a calendar of future events you would check that the year is the current year or greater.Parse() to validate a date instead of using reg Ex.Reg Ex for date is actually unwieldy and hard to get right especially with leap years and all.
The function has been improved now so that the day, month and year values are checked to ensure that they're in the right ball-bark (ie. Also the year must be between 1902 and the current year.I need the pattern to be DD/MM/YYYY (day first since it's in spanish and only "/", "-" should not be allowed) I searched several regex libraries and I think this one should work...but since I'm not familiar with regex I'm not sure it validates like that Now you can use this function to check for valid dates; however, if you need to actually validate without rolling (e.g.The code behind the form now is as follows: If you're not already familiar with regular expressions, then this might be getting a bit complicated.Basically, for each of the regular expression tests, an array is returned holding each component of the pattern that we've matched.