How to add alphabets without space validation in magento?
-
12-12-2019 - |
Question
There are validate-alpha
and validate-alphanum-with-spaces
classes in magento form validation .
But how to do only validate-alpha-with-spaces
?
Solution
Reference: Magento validation class
You can create you own custom validation class
<script type="text/javascript">
var theForm = new VarienForm('theForm', true);
Validation.add('validate-alpha-spac','You failed to enter baz!',function(v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9 ]+$/.test(v)
});
</script>
See http://magento-quickies.tumblr.com/post/6579512188/magento-custom-form-validation
or
Validation.addAllThese([
'validate-alpha-space',
'Please use letters only (a-z or A-Z) in this field.',
function (v) { return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9 ]+$/.test(v)
}]),
see http://blog.baobaz.com/en/blog/custom-javascript-form-validators
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange