限制并将文本输入到angular.js中的特定语言字符 [英] restrict and input text to a specific language characters in angular.js

查看:79
本文介绍了限制并将文本输入到angular.js中的特定语言字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am building a form using 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>

我正在建立一个注册表格,我将有2个字段:
名字和最后一个应仅使用特定语言(非英语)输入的名称。
说明:除了表格接受该语言外,没有其他语言。

i am building a register form inside i will have 2 fields: first name and last name that should be entered only with a specific language (not english). explanation: no other language except that language will be accepted by the form.

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

all other fields will have to be in english.

谢谢

推荐答案

这是一个很好的问题。

This is a good question.

您可以检查此语言的Unicode块这里,我想这是希伯来语,所以代码范围是 0590-05FF

You can check the Unicode block for this language here, I guess it is Hebrew, so the code range is 0590-05FF.

然后您可以使用ngPattern进行如下验证:

Then you can use ngPattern to do the validation like this:

<input type="text" name="firstName" ng-model="register.firstName" placeholder="שם פרטי" required ng-pattern="pattern"></div>

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

以下是演示

这篇关于限制并将文本输入到angular.js中的特定语言字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆