0

Currently, I use the following expression for my ngPattern attribute: /[^*]/ meaning that any input is allowed but it has to contain at least one char different from *. Now, additional requirement arose - the input has to be numeric only.

Is there any possibility to combine these two requirements in one single regular expression? I just can't get it... Or should I move the condition check to my controller, where I would apply two regular expressions consecutively, programmatically.

Ewgenij Sokolovski
  • 897
  • 1
  • 12
  • 31

2 Answers2

0

Do you want the input to be numeric, but * is also allowed? If so, this will do the trick:

<input type="text" ng-pattern="[1-9\*]*">

In general, you can do most stuff in regex, so there is no need to take it to the controller.

Martin Gottweis
  • 2,721
  • 13
  • 27
  • That wouldn't work for me :-) \* is allowed but it is not allowed to be the only type of char in the input. * or **** or ******** are not allowed. But abcd\*fgh or abcd\*\*\*\*fdh are allowed. Therefore I used /[^*]/ before. – Ewgenij Sokolovski May 22 '16 at 20:19
0

OK, I asked a colleague of mine today. Here is the right solution: /[\d*]*\d[\d*]*/

Ewgenij Sokolovski
  • 897
  • 1
  • 12
  • 31