Magento has awesome Javascript validation library, which can be initialized var myForm= new VarienForm('[your form id]', true);
. However this validation function is triggered when one click on submit button.
Is not there way to validate particular field as you type. For example if I type postal code 2 digit and go to second field, it should instantly validate postal code and show error. As postal code require at least 5 digits.
thanks
Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data. Data Format Validation − Secondly, the data that is entered must be checked for correct form and value.
You can use regular expressions to match and validate the text that users enter in cfinput and cftextinput tags. Ordinary characters are combined with special characters to define the match pattern. The validation succeeds only if the user input matches the pattern.
Yes, Magento provide awesome validation library. You can call validation for each field with `validate' method.
For example to validate zip code, you can observe blur event and call validate
method.
$('billing:postcode').observe('change', function(e){
Validation.validate($('billing:postcode'))
})
Notice Validation.validate($('billing:postcode'))
, this will call validation for postcode field.
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