jquery - Regex for Date Validation in javascript -
pls can give date validation regex, allow following rules are
- it should allow mm/dd/yyyy, m/d/yyyy, mm/d/yyyy, m/d/yyyy (not allow yy)
- number of days month (30 , 31) validation.
- feb month validation leap & non leap years.
try this:
([0-9][1-2])/([0-2][0-9]|[3][0-1])/((19|20)[0-9]{2})
and if got valid string above regex string manipulations, below:
if(/([0-9][1-2])\/([0-2][0-9]|[3][0-1])\/((19|20)[0-9]{2})/.test(text)){ var tokens = text.split('/'); // text.split('\/'); var day = parseint(tokens[0], 10); var month = parseint(tokens[1], 10); var year = parseint(tokens[2], 10); } else{ //show error //invalid date format }
Comments
Post a Comment