How can I specify a custom date formate to be validated with the Validation Plugin for jQuery?
Below jQuery code shows exactly the same thing. $(function() { $('#btnSubmit'). bind('click', function(){ var txtVal = $('#txtDate'). val(); if(isDate(txtVal)) alert('Valid Date'); else alert('Invalid Date'); }); });
The toISOString() method returns a string formatted as YYYY-MM-DDTHH:mm:ss. sssZ . If the ISO representation of the Date object starts with the provided string, then the date string is valid and formatted as DD/MM/YYYY .
Validation in JQuery: Using JQuery, a form is validated on the client-side before it is submitted to the server, hence saves the time and reduce the load on the server. Form Validation means to validate or check whether all the values are filled correctly or not.
You can create your own custom validation method using the addMethod
function. Say you wanted to validate "dd/mm/yyyy":
$.validator.addMethod( "australianDate", function(value, element) { // put your own logic here, this is just a (crappy) example return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/); }, "Please enter a date in the format dd/mm/yyyy." );
And then on your form add:
$('#myForm') .validate({ rules : { myDate : { australianDate : true } } }) ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With