i have been using regex pattern validation angularjs last several versions , has worked fine.
my application requires validation patterns exposed scope property, corresponding angularjs validation directive bound. prior v1.3, looked this:
// on controller $scope.validationpattern = "^\\d*$"; // allow numeric digits <!-- in html page ---> <input type="text" name="age" ng-pattern="/{{validationpattern}}/" /> having updated angularjs v1.4 (bypassing v1.3), find above approach no longer works. looking @ migration notes v1.3, see expected behavior , new approach required, looks this:
// on controller $scope.validationregexp = /^\d*$/; // use regexp instead of string <!-- in html page ---> <input type="text" name="age" pattern="{{validationregexp}}" /> however, can't work. if place validation pattern inline (within html input element) works fine, when moved onto scope object , bound pattern or ng-pattern directive, no validation occurs.
here's jsfiddle demonstrates problem.
any suggestions please?
you should use name of scope variable:
<input type="text" name="age" ng-pattern="validationpattern" />
Comments
Post a Comment