future future - 1 year ago 140
AngularJS Question

ng-pattern Validation not working

I am trying to do validation with angular and Bootstrap but for some reasons ng-pattern validation is not working in Zip Code. Any help will be great in this.


Not able to paste full code, but here is how I am attempting to use the


<input type="text" class="form-control" id="zipCode" name="zipCode"
ng-model="auth.zip" ng-pattern="^(\d{5}-\d{4}|\d{5})$" required="">

Answer Source

The problem is that when you place the pattern inline instead of a scope variable it expects / around the regex, like a litteral.

Like this:



See the input docs, check out the arguments section then ngPattern

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download