Changing the validation rules for all forms
-
12-12-2019 - |
Question
I want to change the rules in all magento forms, to accept just English characters. So any non-english character in magento form should not be accepted. any suggestion how I could do it?
Solution
I Added this code inside validation.js
located in js\prototype
Validation.add('validate-english-alphanum-with-spaces', 'Please use only english letters', function(v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9 ']+$/.test(v)
});
Then edit the forms css class in frontend\yourtheme\template\persistent\checkout\onepage\billing.phtml
add validate-english-alphanum-with-spaces
to the class
Note: This will change the validation in the client side, you have to change Zend validation rules to change the validation in the server side.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange