Confirm UTF-8 names with angular and ngPattern

Is there a way to use the ng-template in form validation to validate any letter from any alphabet (Latin, Chinese, Korean, Russian, ...).

I found a solution with the XRegExp library, but I will not work with the ng-sample, since it expects a string regular expression.

XRegExp("^\\p{L}[\\p{L} ']*$")

One solution builds my own validator directive too much, but I would prefer to use ng-pattern if possible.

+5
source share
2 answers

You can use this regular expression in ng-sample. You just need to pass the regular expression literal as a string like this:

 ng-pattern="/^\\p{L}[\\p{L} ']*$/" 
0
source
 ng-pattern="/^.{3,20}$/" 

allow any characters (including utf-8) and limit 3-20 characters, or

 ng-pattern="/^.[^*?&]{3,20}$/" 

allow any characters and limit character 4-20 and except *? & (add more characters to exclude)

0
source

Source: https://habr.com/ru/post/1205324/


All Articles