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

Comments

Popular posts from this blog

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development

Angular.js ng-click with mouse middle button

Using Intervention package to compress images. My images are not being compressed, still the same size - development