Prashant Prashant - 5 months ago 11
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
"asd"
or
"09"
although I am expecting both should be accepted. Is this pipe symbol
|
not working as OR?

Answer

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.