I have to validate a field that allows just words, spaces, and the characters "&" and "-".
The regex I'm using is /[A-Za-z\s\b-&]+/g.
Here is the code:
$('#register_validator').bootstrapValidator({
framework: 'bootstrap',
fields: {
name: {
validators: {
regexp: {
regexp: /[A-Za-z\s\b-&]+/g,
message: 'Invalid character'
}
}
}
When I write a valid string and then I erase a character, it triggers the validator.
For example:
text: Jones -> OK
erase a char: Jone -> message: Invalid character
Is there something wrong with the regEx? What can I do to avoid this bug?
I've solved the problem with
/^[a-zà-ú\s-&üû]+$/iIt allows the alphabet, extended chars, spaces and the special chars
&and-.Thanks!