Sunday, October 1, 2017

angularjs ng-pattern regex for 4 digits and 2 decimal

I am trying to create a Regex for a number with maximum 4 digits and if the input has decimal it has to have 2 digits – .20 and not .1.
tried:

ng-pattern="/^[0-9]+(.[0-9]{1,2})?$/" //fail for 666666, .10, .1

Examples for valid inputs:

100.10
100
3000.10

Example for invalid:

10000 //has more then 4 digits before decimal
100.1 //has only 1 digit after decimal
.10 //has no digits before decimal

Thanks for any help.

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/01/angularjs-ng-pattern-regex-for-4-digits-and-2-decimal/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment