【发布时间】:2017-05-28 21:13:49
【问题描述】:
我想在<input> 上设置一些验证,以防止用户输入错误的字符。为此,我使用ng-pattern。它目前禁止用户输入错误的字符,但我也注意到这不是预期的行为,所以我还计划创建一个指令。
我正在使用
AngularJS:1.6.1
正则表达式应该匹配什么
以下是正则表达式字符串的要求:
- 数字 0x 到 xx(例如 01 到 93)
- 数字 x 到 xx(例如 9 到 60)
- 不允许使用字符
- 不允许使用特殊字符
注意: “x”是可变的,可以是 0 到 100 之间的任何数字。
'x' 位置上的数字是可变的,所以如果可以创建一个易于更改的字符串,将不胜感激!
我尝试了什么
我尝试过的一些正则表达式字符串在哪里:
1)^0*([0-9]\d{1,2})$
--> Does match 01 but not 1
--> Does match 32 where it shouldn't
2)^[1-9][0-9]?$|^31$
--> Does match 1 but not 01
--> Does match 32 where it shouldn't
为了测试我使用https://regex101.com/tests。
我在尝试中遗漏了什么?
【问题讨论】:
标签: javascript html angularjs regex