Hello,
I would like to know how can i allow spaces in the alpha validation?
Beacuse I have some text with spaces.
Thank you,
Regards,
I would like to know how can i allow spaces in the alpha validation?
Beacuse I have some text with spaces.
Thank you,
Regards,
Hi others,
You'll need to hack the validation JavaScript for this. In MooValidation.js around line 197* you'll find a snippet of RegExp like this /^[a-zA-Z]+$/. You can either hack this to allow spaces - Beware this will affect all alpha validation on your site; or, you can add a custom validation - Instructions for this are on Andrew Tetlaw's Dexagogo site (look for Really Easy Validation).
Bob
If you are using the Prototype library you'll need to look in validation.js instead.
You'll need to hack the validation JavaScript for this. In MooValidation.js around line 197* you'll find a snippet of RegExp like this /^[a-zA-Z]+$/. You can either hack this to allow spaces - Beware this will affect all alpha validation on your site; or, you can add a custom validation - Instructions for this are on Andrew Tetlaw's Dexagogo site (look for Really Easy Validation).
Bob
If you are using the Prototype library you'll need to look in validation.js instead.
So, is this the expression?
/^[a-zA-Z]+\s+$/
Before
['validate-alpha', 'Please use letters only (a-z) in this field.', function (v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+$/.test(v)
After
['validate-alpha', 'Please use letters only (a-z) in this field.', function (v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+\s+$/.test(v)
Thanks.
/^[a-zA-Z]+\s+$/
Before
['validate-alpha', 'Please use letters only (a-z) in this field.', function (v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+$/.test(v)
After
['validate-alpha', 'Please use letters only (a-z) in this field.', function (v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+\s+$/.test(v)
Thanks.
you mean you got it working or it doesn't work ?
Hi blindman,
I think that the space needs to be inside the square brackets so that the regexp becomes /^[a-zA-Z ]+$/ but note that this will match an entry with *only* spaces. (Your version will match an alpha-string followed by a string of spaces.)
Bob
I think that the space needs to be inside the square brackets so that the regexp becomes /^[a-zA-Z ]+$/ but note that this will match an entry with *only* spaces. (Your version will match an alpha-string followed by a string of spaces.)
Bob
This topic is locked and no more replies can be posted.