在 angular.js 中限制和输入文本到特定语言字符

lob*_*3rd 4 javascript angularjs

我正在使用 angular.js 构建一个表单。

我的表格看起来像:

<form name="registerForm" class="form-horizontal">
    <div class="control-group">
        <label class="control-label">?? ????</label>
        <div class="controls">
            <input type="text" ng-model="register.firstName" placeholder="?? ????" required>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">?? ?????</label>
        <div class="controls">
            <input type="text" ng-model="register.username" placeholder="?? ?????">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">???"?</label>
        <div class="controls">
            <input type="email" ng-model="register.email" placeholder='???"?'>
        </div>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

我正在构建一个注册表,我将有 2 个字段:名字和姓氏,只能使用特定语言(不是英语)输入。解释:表格不接受除该语言之外的其他语言。

所有其他字段都必须是英文。

谢谢

zs2*_*020 7

这是一个很好的问题。

你可以在这里检查这种语言的 Unicode 块,我猜它是希伯来语,所以代码范围是0590-05FF.

然后你可以使用 ngPattern 来做这样的验证:

<input type="text" name="firstName" ng-model="register.firstName" placeholder="?? ????" required ng-pattern="pattern"></div>

function ctrl($scope) {
    $scope.pattern = /[\u0590-\u05FF]+/g;
}
Run Code Online (Sandbox Code Playgroud)

Here is the demo