Luke Flournoy
Luke Flournoy

Reputation: 3733

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

Upvotes: 1

Views: 1375

Answers (1)

Little Santi
Little Santi

Reputation: 8783

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.

Upvotes: 2

Related Questions