Iam trying to write form validation to input type number,but Iam getting error message even Iam entering numbers also.Can we write form validation for input type="number"?Or is there any other way for declaration in angularjs? Here is my code:
<form name="validation"> <input type="number" ng-model="cost" name="cost" ng-pattern="/^[0-9]*$/"><span ng-show="validation.cost.$error.pattern" style="color:red">Enter numbers only</span> </form>
You can update the regex for accepting both number and decimals. Just update the regex to /^[0-9]+([,.][0-9]+)?$/
. I have added a working fiddle for your understanding here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.