admin管理员组文章数量:1302383
i am building a form using angular.js.
my form looks like:
<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>
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.
thanks
i am building a form using angular.js.
my form looks like:
<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>
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.
thanks
Share Improve this question edited Aug 16, 2013 at 19:05 zs2020 54.5k30 gold badges156 silver badges223 bronze badges asked Aug 16, 2013 at 9:44 lobengula3rdlobengula3rd 1,8615 gold badges27 silver badges39 bronze badges 1- Modified @zsong answer to Hebrew/English/Arabic validation (without english numbers) - Enjoy: jsfiddle/yossico/3hefL0yp – yossico Commented Dec 4, 2016 at 13:53
2 Answers
Reset to default 7This is a good question.
You can check the Unicode block for this language here, I guess it is Hebrew, so the code range is 0590-05FF
.
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;
}
Here is the demo
I think Regex is the way to go.
HTML5 has the new pattern attribute that you could use to validate the user input, the only problem is that you also have to take care of browsers that do not support it, with Angular you can use the ngPattern directive.
This question will help you with the regex.
Remember that this is just the front-end validation and I remend you to validate the user input in the back-end as well.
本文标签: javascriptrestrict and input text to a specific language characters in angularjsStack Overflow
版权声明:本文标题:javascript - restrict and input text to a specific language characters in angular.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741686506a2392472.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论