1

我希望我的输入字段之一恰好有 10 位数字。我ng-pattern以下列方式使用过

<input type="text" ng-pattern="/[1-9]{1}[0-9]{9}$/" ng-model="user.Identity" name="identity">

问题是这个表达式允许用户输入超过 10 位的数字字符串,而我想只允许 10 位数字。我的正则表达式或我的理解有问题ng-pattern吗?

4

1 回答 1

5

^锚点指示字符串/行的开头,就像结尾一样$^expr$防止您看到的移动窗口匹配:

/^[1-9]{1}[0-9]{9}$/
于 2015-03-24T14:57:48.823 回答