Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用带有unicode字符的ng模式(Angular.JS)的不良结果_Javascript_Regex_Angularjs_Unicode - Fatal编程技术网

Javascript 使用带有unicode字符的ng模式(Angular.JS)的不良结果

Javascript 使用带有unicode字符的ng模式(Angular.JS)的不良结果,javascript,regex,angularjs,unicode,Javascript,Regex,Angularjs,Unicode,我使用的是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.

我使用的是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">

现在,对于大多数输入,该模式将起作用,并且不会用错误的结果(如:“abcd”)填充$scope.firstname

但也有一些输入,如“שדas”,出于某种原因,这些输入正被模式所接受

我相信问题在于模式定义。一定是出了什么问题,但我确信u05D0-u05F3确实是我在模式中需要的范围。那么我的问题是什么呢?

试试这个:

$scope.onlyHebrewPattern=/^[\u05D0-\u05F3]+$/g


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

看起来ng模式匹配的是一个值的开头,而不是整个值。看来这解决了问题。你能解释一下为什么这样做吗?特殊的正则表达式字符“^”和“$”分别表示“仅在开头”和“仅在结尾”。您所说的模式“匹配包含(希伯来文字符)的字符串”(一次或多次)。但“ab(希伯来文)”与该描述匹配-它包含一个希伯来文字符。使用(仅在开始时)(希伯来文)(一次或多次)(仅在结束时)迫使所有的字符都是希伯来语,因为希伯来文的字符必须在开始和结尾的旁边,中间不能有任何非希伯来语字符。嘿,我不知道为什么,但是这个模式不适合它的工作。有时输入的OK会因为某种原因被拒绝。原因是什么?如果我想添加放置“-”和“'”字符的选项,我将如何将它们添加到regexp模式中?如果您不提供一些信息,我就看不出有什么问题。用一个仍然不起作用的示例更新问题如何。要添加更多允许的字符,请将它们列在方括号内。”-“应该在开头,如下所示:/^[-'\u05D0-\u05F3]+$/g