Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undesirable result of use of ng-pattern (Angular.JS), with unicode characters

I am using an ng-pattern that with an input field that should accept only Hebrew characters.

I have find out what unicode numbers Hebrew chars are.

This is my pattern:

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

And my form input:

<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">

Now for most inputs that pattern will work and will not populate the $scope.firstname with wrong results like: "abcd".

But there are inputs like: "שדas" that for some reason are being accepted by the pattern.

I believe the problem relies with the pattern definition. Something must be wrong but I am sure that u05D0-u05F3 is really that range that I need in my pattern. So what is my problem here?

like image 979
lobengula3rd Avatar asked Jan 30 '26 17:01

lobengula3rd


1 Answers

Try this:

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

Yours matches any string with a Hebrew character.

like image 128
TimK Avatar answered Feb 02 '26 10:02

TimK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!