I need to limit an input box to either accept a number or a certain string pattern
<input type="text" ng-model="value" name="value" ng-pattern="/^([0-9])|([R])$/" required>
This does not seem to fully work, i can add 555f and this will be a valid value for my ng-model
How can i limit this to either match a digit or my string pattern?
You have a problem with your reg exp in
ng-pattern
, this:/^([0-9])|([R])$/
will mach any string that starts from a number or ends with 'R'. And for what you want, you need smth like this:/^[0-9]+$|^[R]+$/
It will match any string that is number, or starts and ends with 'R'.