Prashant Prashant - 9 months ago 26
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?


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.