使用带有 unicode 字符的 ng-pattern (Angular.JS) 的不良结果

Undesirable result of use of ng-pattern (Angular.JS), with unicode characters

本文关键字:JS Angular 不良 结果 ng-pattern unicode 字符      更新时间:2023-09-26

我正在使用一种ng模式,其输入字段应仅接受希伯来语字符。

我已经找出了希伯来字符的统一码数字是什么。

这是我的模式:

$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;

您的字符串匹配任何带有希伯来语字符的字符串。