Luke Flournoy Luke Flournoy - 16 days ago 6
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

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" />

See html5pattern.com.

Comments