0

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?

http://jsfiddle.net/DaleS/dv7vuecz/

Rasalom
  • 3,101
  • 3
  • 21
  • 29
Dale
  • 352
  • 2
  • 15

2 Answers2

0

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'.

Rasalom
  • 3,101
  • 3
  • 21
  • 29
0
^([0-9]|[R])$

Try this.See demo.

https://regex101.com/r/eZ0yP4/10

vks
  • 67,027
  • 10
  • 91
  • 124