简体   繁体   中英

AngularJs text input field regular expression

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM