Recently, when I was using the mvc4 development project, I suddenly encountered a strange bug, that is, when I used the validate. js built-in mvc4 to verify datetime, I always reported an error (for example ).
After repeated tests, I found the following problems:
1. If the date format is "2012/10/22", the verification will pass.
2. verification errors may occur in IE 6, 7, 8, and other browsers. Similar bugs are not found in ie9 and Firefox (latest.
To sum up, I checked the information online and finally saw a post like demo. tc/post/762.
In short, this is a bug.
The specific solution is as follows:
Create a new JS file: jquery. Validate. Plus. js
Jquery. validator. Methods. Date = function (value, element ){
Return this. optional (element) | (/^ \ D {4} [\/-] \ D {1, 2} [\/-] \ D {1, 2} $ /. test (value ));}
Then, when referencing the JS library, you can do this:
<SCRIPT type = "text/JavaScript" src = "/scripts/jquery. Validate. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/scripts/jquery. Validate. Plus. js"> </SCRIPT>