【发布时间】:2013-10-23 22:11:41
【问题描述】:
我正在使用一个 ng 模式,它的输入字段应该只接受希伯来字符。
我找到了希伯来字符的 unicode 数字。
这是我的模式:
$scope.onlyHebrewPattern = /[\u05D0-\u05F3]+/g;
还有我的表单输入:
<input tabindex=1 type="text" ng-disabled="disableButtons" name="firstname" ng-minlength="2" ng-maxlength="15" ng-model="register.firstName" placeholder="first name" ng-pattern="onlyHebrewPattern" required title="please enter your name">
现在对于大多数输入,该模式将起作用,并且不会在 $scope.firstname 中填充错误结果,例如:“abcd”。
但有一些输入,例如:“שדas”,由于某种原因被模式所接受。
我相信问题取决于模式定义。一定有问题,但我确信 u05D0-u05F3 确实是我在模式中需要的范围。那么我的问题是什么?
【问题讨论】:
-
看起来 ng-pattern 匹配一个值的开头,而不是整个值。见stackoverflow.com/questions/18746913/…
标签: javascript regex angularjs unicode