Value of the text box to allow only decimals and numbers using ng-pattern?


In my code I need to allow decimals and integers. How can I check this using ng-pattern?

example code

my test cases

1)22 = pass,

2)22.5 = pass,

3)2a = fail,

4)@#@ = fail

ng-pattern takes a string.

The string is regex so give this a shot


It allows decimal and whole numbers.

To check it works properly I pasted it into this

You can also use it to check any modifications you would like to add.

Also as Tushar said you could have this


since \d is the same as [0-9] in regex.