jquery - Regex for Date Validation in javascript -


pls can give date validation regex, allow 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 month (30 , 31) validation.
  3. 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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -