A regular expression can be a single character, or a more complicated pattern.
Regular expressions can be used to perform all types of text search and text replace operations.
[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?
[1-9] # 01-09 or 1-9 | # .1[012] # 10,11,12 ) # end of group #2 / # follow by a "/" ( # start of group #3 (19|20)\d\d # 19[0-9][0-9] or 20[0-9][0-9] ) # end of group #3 The above regular expression is used to validate the date format in “dd/mm/yyyy”, you can easy customize to suit your need.
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.
I think with some adjustment, you could have reasonable validation of dates, which I would like to see you do, but half validating them seems to me like having a weak fence on a cliff edge, better to have none at all, lest someone leans on it! Above function can validate YYYY-MM-DD, DD-MM-YYYY date formats.
“29/a/2008”, “a/02/2008” – month is invalid, day is invalid 6.
“30/2/2008”, “31/02/2008” – leap year in February has 29 days only 5.
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.
The following example searches a string for the character "e": The exec() method is a Reg Exp expression method.