I use ng-pattern="/0-9/"
to set price_field
do not accept decimal number
. But when I input natural number (from 0 to 9999999),ng-show
gets activated with Not valid number!
.
Where did I go wrong?. Please help.
I use ng-pattern="/0-9/"
to set price_field
do not accept decimal number
. But when I input natural number (from 0 to 9999999),ng-show
gets activated with Not valid number!
.
Where did I go wrong?. Please help.
The problem is that your REGX pattern will only match the input "0-9".
To meet your requirement (0-9999999), you should rewrite your regx pattern:
ng-pattern="/^[0-9]{1,7}$/"
My example:
HTML:
JS:
function formCtrl($scope){ $scope.onSubmit = function(){ alert("form submitted"); } }
Here is a jsFiddle demo.
This is working
Phone is required.
the following code will help for phone number validation and the respected directive is
app.directive('validatePhone', function() { var PHONE_REGEXP = /^[789]\d{9}$/; return { link: function(scope, elm) { elm.on("keyup",function(){ var isMatchRegex = PHONE_REGEXP.test(elm.val()); if( isMatchRegex&& elm.hasClass('warning') || elm.val() == ''){ elm.removeClass('warning'); }else if(isMatchRegex == false && !elm.hasClass('warning')){ elm.addClass('warning'); } }); } } });