我正在使用一个 ng-pattern,它的输入字段应该只接受希伯来语字符。
我找到了希伯来字符的 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 确实是我在我的模式中需要的范围。那么我的问题是什么?
最佳答案
试试这个:
$scope.onlyHebrewPattern =/^[\u05D0-\u05F3]+$/g;
你的匹配任何带有希伯来字符的字符串。
关于javascript - 使用带有 unicode 字符的 ng-pattern (Angular.JS) 的不良结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19392528/