Regular expression validation error

I use regex to check numbers in angularjs. But my code shows a validation error when the number exceeds 9 digits. Maybe someone will ask me to correct my code so that you can enter any digits of the number.

I tried:

ng-pattern="/^\d{0,9}?$/"
+4
source share
4 answers

Just delete {0.9}? and use * instead

/^\d*$/

{0.9} means any length between 0 and 9

+3
source

I suspect the problem is understanding the difference between:

  • {0,9}
  • [0-9]

{0,9} means "from zero to 9 repetitions of the previous term", which in this case means "from zero to 9 digits".

[0-9] " 0 9 ()", \d.

Try:

/^\d+$/

" " .

, :

/^\d+(\.\d+)?$/

, " , ".

+3

{0,9} *. ? - :

ng-pattern="/^\d*$/"

:

ng-pattern="/^\d*(\.\d+)?$/"
+2

:

  "/^\d*?$/"

\d{0,9}= 0 9

\d*= 0 N

\ d = : 0 1 2 3 4 5 6 7 8 9

+1

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


All Articles