if text box value preceed with .(dot) it sh" /> if text box value preceed with .(dot) it sh" /> if text box value preceed with .(dot) it sh"/>

Html pattern text input validation ng-pattern="/^-?[0-99]+(.[0-99]{0,2})?$/"

138 Views Asked by At
<input type="text" ng-model="price" name="price_field" ng-pattern="/^-?[0-99]+(.[0-99]{0,2})?$/" required>

if text box value preceed with .(dot) it should append 0(Zero) for example: .50 => result should be 0.50 also if it is 5. it should be 5.0

1

There are 1 best solutions below

0
Prashanth Subramanian On BEST ANSWER

ng-pattern="/^-?([0-9]{0,2})+(.[0-9]{0,2})?$/" Use this pattern which will allow .5 and 5. You have to have some kind of solution to handle this number in backend .ng pattern cant convert .5 to 0.5. you can use Number funtion to achive this .