Luke Flournoy Luke Flournoy - 1 year ago 69
AngularJS Question

How to restrict an html input to positive decimal numbers up two decimals?

I am writing a angularjs app and am trying to restrict an html tag to positive float numbers with up to 2 decimal places.

code I have now...

<input type='number' min='.01' ng-model='threshold' />

Answer Source

You could use the pattern attribute to set a proper regular expression. For example:

<input name="x" pattern="[0-9]+(\.[0-9][0-9]?)?" placeholder="000.00" />


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download