skip to content »

Regular expression for validating date in javascript

Regular expressions can be used to perform all types of text search and text replace operations.

However, it’s a bit hard to validate the leap year , 30 or 31 days of a month, we may need basic logic as below. q=Regular expression for validating Date format dd/MM/yyyy&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Hi Rameez, Checkout Patterns.aspx? [1-9] # 01-09 or 1-9 | # .[12][0-9] # 10-19 or 20-29 | # .3[01] # 30, 31 ) #end of group #1 / # follow by a "/" ( # start of group #2 0? The search() method uses an expression to search for a match, and returns the position of the match.The replace() method returns a modified string where the pattern is replaced. It searches a string for a pattern, and returns true or false, depending on the result.You can concatenate simple regular expressions into complex search criteria to validate against complex patterns, such as any of several words with different endings.

You can use Cold Fusion variables and functions in regular expressions.

“333/2/2008”, “29/02/200a” – day is invalid, year is invalid 7.

“29/a/2008”, “a/02/2008” – month is invalid, day is invalid 6.

“31/6/2010”, “31/06/2010” -June has 30 days only 9.

“31/4/20100”, “31/04/2010” – April has 30 days only 8.

The validation succeeds only if the user input matches the pattern.