Prashant Prashant - 1 year ago 69
AngularJS Question

Why is Or not working in angularJs ng-pattern?

I am using the

ng-pattern="/^(([A-Za-z]{0,5}) | ([0-9]{0,10}))$/"
but the input control rejecting the input
although I am expecting both should be accepted. Is this pipe symbol
not working as OR?

Answer Source

You are using a scope variable, so, if you have ng-pattern="regex" in the input, use

$scope.regex = /^([A-Za-z]{0,5}|[0-9]{0,10})$/;

The spaces around | are considered meaningful and are search for by the regex engine.

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