I'm quite new with regular expression, i'm using it in angularjs. I need to check an input field, and I need to accept only positive decimal values with no more than 3 digits after the point:
3
3.5
3.567
0.236
and reject values like
0
0.
.
.6
.635
3.6589
I tried this regexp:
var result = /([1-9]\d*)\.(\d{1,3})/.test(value) || /[1-9]\d*(?=\s|$)/.test(value);
and more or less it works, but still
- it accepts values with more than 3 digits after the point, like
45.9876
- it accepts
.356
values (a number starting with.
)
what I'm missing?