User_MVC User_MVC - 1 year ago 90
Javascript Question

Regex for Date Validation in javascript

pls can somebody give the date validation regex, which will allow the following rules are

  1. It should allow mm/dd/yyyy, m/d/yyyy, mm/d/yyyy, m/d/yyyy (not allow yy)

  2. Number of days for month (30 and 31) validation.

  3. Feb month validation for leap & non leap years.

Answer Source

Try this:


and then if you got a valid string from the above regex then with string manipulations, do something like below:

    var tokens = text.split('/');  //  text.split('\/');
    var day    = parseInt(tokens[0], 10);
    var month  = parseInt(tokens[1], 10);
    var year   = parseInt(tokens[2], 10);
    //show error
    //Invalid date format
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download