1

I created a custom jQuery Validate rule:

jQuery.validator.addMethod(
        "regex",
        function(value, element, regexp) {
            var re = new RegExp(regexp);
            return this.optional(element) || re.test(value);
        },
        "Please check your input."
    );

And now would need regex to match only letters (in any language, especial Czech)

I tried

regex: "/^\pL++$/uD"

regex: "^\w*(\s\w*)?$"

None of these work. What would be the correct regex?

user1049961
  • 2,656
  • 9
  • 37
  • 69

1 Answers1

2

That's because JS doesn't natively support unicode categories. You can take a look here for more info on this.

Alternatively you could specify a unicode character class with different ranges if you didn't need to know whether or not a unicode character was a "letter" or not. For example:

^[\u0000-\u024F]+$

would ensure the string contains only control characters and all forms of latin characters including all extensions. You can refer here for more characters and ranges.

Community
  • 1
  • 1
tenub
  • 3,386
  • 1
  • 16
  • 25