Reputation: 1746
I need to validate username. The user name should allow only characters and spaces. It should not accept numbers. The current validation class which allows numbers. But if I use class "validate-alpha" which is not allowing spaces. Can any one tell me which validation class should I use?
Upvotes: 1
Views: 3200
Reputation: 17656
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
Upvotes: 4