> I have a date filed that needs to be validated only for > one type of date format: mm/dd/yyy. > is there a way to restrict that to only one format?
This should work for validating USA-style mm/dd/yyyy dates. $.validator.addMethod("usadate", function(value, element){ // Start with basic match for digits and slashes var mdy = value.match(/(\d{1,2})\/(\d{1,2})\/(\d{4})/); if ( !mdy ) return false; // Use Javascript date constructor to check the date var dt = new Date(mdy[3], mdy[1]-1, mdy[2]); if ( isNaN(dt) ) return false; // JS allows 12/99/2008; see if month or year changed return +mdy[1] == dt.getMonth()+1 && +mdy[3] == dt.getFullYear(); }, "Please enter a valid date in the form mm/dd/yyyy." );