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
Add a ment  | 

2 Answers 2

Reset to default 7

This 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