Reputation: 1061
i need to check the given the input text doesnot contain full zeors in ng-pattern. for eg my I/p is :00002210000 it should accept if my I/p is:0000000000 it should not accept it should throw an error.
Upvotes: 0
Views: 1047
Reputation: 3758
Use javascript match().
if (!myString.match(/(0*[1-9]+0*)+/) {
alert("Invalid string!");
};
The above requires the input to have at least one non-zero number. Here's a fiddle to demonstrate with ng-pattern as requested:
http://jsfiddle.net/HB7LU/15632/
<input ng-model="myText" ng-pattern="/^(0*[1-9]+0*)+$/" type="text" />
Upvotes: 2
Reputation: 12103
It is better to put regex in your controller $scope variable, and bind it inside ng-patter.SEE THIS
$scope.regex = /([0]+[1-9]+[0]+)?$/;
ng-pattern="regex";
OR,
ng-pattern="^([0]+[1-9]+[0]+)?$"
Upvotes: 1
Reputation: 1022
You could use a regEx pattern that checks if the input contains at least one number:
ng-pattern=".*[0-9].*"
RegEx is from Regular Expression For At Least One Number
Upvotes: 0