0

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?

4

1 回答 1

0

我已经解决了这个问题/^[a-zà-ú\s-&üû]+$/i

它允许字母表、扩展字符、空格和特殊字符&-.

谢谢!

于 2018-08-23T18:58:33.250 回答