Is there a way to use ng-pattern in form validation to validate any letter from any alphabet (latin, chinese, korean, russian, ...).
I found a solution with the XRegExp library, but will not work with ng-pattern since it is expecting a string regex.
XRegExp("^\\p{L}[\\p{L} ']*$")
One solution is too build my own validator directive, but I would prefer to use ng-pattern if possible.
You need to add the u flag for Unicode support. That way you can specify patterns that include character categories, such as \p{L} for a letter in any language, \p{M} for an accent mark in any language.
Example:
ng-pattern="/^[\\p{L}\\p{M}][\\p{L}\\p{M}\\p{Zs}'\\-]*$/u"
Explanation:
[\p{L}\p{M}] -- any letter in any alphabet, including accent mark\p{Zs} -- space separator in any language', and - at the end, you can tweak the pattern if you want to avoid thatSee details on Unicode and character categories at https://javascript.info/regexp-unicode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With