Format is day/month/year
The code is as follows |
Copy Code |
Date format [' Date_au ', function (v) { if (vanadium.validators_types[' empty '].test (v)) return true;
var regex =/^ (d{2})/(D{2})/(d{4}) $/; if (!regex.test (v)) return false; var d = new Date (V.replace (Regex, ' $2/$1/$3 ')); Return (parseint (regexp.$2) = = (1 + d.getmonth ()) && (parseint (regexp.$1, 10) = = D.getdate ()) && (parseint (regexp.$3,) = = D.getfullyear ()); }, |
' Please enter the correct date format, for example: 28/05/2010. '],
How to change the format to adult-month-day, or month-day-year
The code is as follows |
Copy Code |
/** Determine the date format entered in the input box is YYYY-MM-DD and the correct date */ function IsDate (sm,mystring) { var reg =/^ (d{4})-(D{2})-(d{2}) $/; var str = mystring; var arr = reg.exec (str); if (str== "") return true; if (!reg.test (str) &®exp.$2<=12&®exp.$3<=31) { Alert ("Please ensure that the date format entered in +sm+ is YYYY-MM-DD or the correct date!"); return false; } return true; } |
Example 2
The code is as follows |
Copy Code |
Check date format, valid format for example: 2000-10-29, month and day must be two bits, can detect leap years. function IsDate (str) { var reg=/^ (?:(?! 0000) [0-9]{4}-(?:(?: 0 [1-9]|1[0-2])-(?: 0 [1-9]|1[0-9]|2[0-8]) | (?: 0 [13-9]|1[0-2])- (?: 29|30) | (?: 0 [13578]|1[02])-31 | (?: [0-9]{2} (?: 0 [48]| [2468] [048]| [13579] [26]) | (?: 0 [48]| [2468] [048]| [13579] [26]) 00)-02-29 $/; if (Reg.test (str)) return true; return false; } |
Example 3
Only allow input to YYYY-MM-DD format.
code is as follows |
copy code |
<script type= "Text/javascript" Function checkdate () { var r =/^(?:(?! 0000) [0-9]{4}-(?:(?: 0 [1-9]|1[0-2])-(?: 0 [1-9]|1[0-9]|2[0-8]) | (?: 0 [13-9]|1[0-2])- (?: 29|30) | (?: 0 [13578]|1[02])-31 | (?: [0-9]{2} (?: 0 [48]| [2468] [048]| [13579] [26]) | (?: 0 [48]| [2468] [048]| [13579][26]) 00)-02-29 $/; if (!r.exec document.getElementById ("Text2″). Value") { Alert ("Please enter a date with the correct format NR date format: yyyy-mm-ddnr example such as: 2010-08-08nr "); return false; } Else { return true; } } </script> JS Decision date format: <br/> <input id= "text2″type=" text/><br/> < Input id= "button2″type=" button "value=" Judgment Date "onclick=" checkdate (); " /> |
For more information, refer to http://www.111cn.net/wy/99/33176.htm