ng-pattern for only hebrew characters - angularjs

I want to use ng-pattern validate my text input field that should accept only Hebrew characters, sometimes the input are ok and sometimes they are being rejected for some reason. (the first one is validate the second letter is not and etc.)
example:
<input type="text" class="form-control" name="firstName" ng-model="Join.firstName" id="firstName" aria-describedby="firstNameHelp" maxlength="15" ng-pattern="onlyHebrewPattern" required>
and the solution that given was:
scope.onlyHebrewPattern = /^[\u05D0-\u05F3]+$/g;
original post

$scope.onlyHebrewPattern = /^[א-ת\s]+$/;

Related

How to use OR with ng-pattern

Here is my Input field where I am using ng-pattern
<input class="form-control" type="text" name="name"
ng-pattern="/(^[A-z]+$) | (^[0-9]*$)/"
required="" ng-model="name"/>
Input from the user should be either a number or alphabets. How to use OR(|) operator with ng-pattern?
Following are valid inputs :
123 (All numbers)
abc (All alphabets)
Following are invalid inputs :
a1
.tgh7
I think you can just combine your two current regex patterns into a single pattern:
<input class="form-control" type="text" name="name"
ng-pattern="/(^([A-z]+|[0-9]+)$)/"
required="" ng-model="name" />
This approach might outperform what you currently have, because it requires evaluating only a single regex pattern, instead of two patterns.
Follow the link below for a demo of the regex:
Regex101

input type number does not add any constraint even set ng-step

I am using input type number and want to allow user only integer value between 1-10 so added ng-step="1" but it still allow float and giving no error
<input type="number"
ng-step="1"
ng-min="1"
ng-max="10"
name="numKeys"
ng-model="vm.data.numKeys"
ng-required class="form-control" />
see this demo
Use ng-pattern with the RegExp "/^[0-9]+$/" to accept only integer values.
<input type="text" ng-model="value" ng-pattern="/^[0-9]+$/">
this just solve my problem
<input type="text" name="numKeys" ng-pattern="/^([1-9]|10)$/" required />

Custom validation for text field

I have the requirement of having the following conditions in a single-line text field:
The first character should be an upper case letter.
The next two characters should be alphanumeric, but any letter should be in upper case.
Given the following code, how can I validate such conditions?
<input
type="text"
maxlength="3"
ng-model="name"
ng-change="name = name.toUpperCase();"
/>
You can force the correct pattern with the ngPattern attribute.
You can't automatically convert a lower case letter typed by your user to upper case with ngChange, since the model is undefined if the input is invalid, but you can use the $parsers instead.
<input
type="text"
ng-model="name"
ng-pattern="'[A-Z][A-Z0-9]{2}'"
/>
If you're using a version between 1.3.0-beta.12 and 1.3.2, use the pattern ^[A-Z][A-Z0-9]{2}$ instead.
If you're using the version 1.3.0-beta.11 or lower, use the pattern /^[A-Z][A-Z0-9]{2}$/ instead.
you can use ng-pattern to set your regular expression and
<input type="text" ng-model="name"
ng-pattern="'^[A-Z][A-Z\d]{2}'"
ng-change="name = name.toUppercase()" />
here you can test or create your regular expressions https://regex101.com/

How to escape string for use in input field using AngularJS

I have a situation where I need to escape the following string to be used as the preloaded value for an input field. I would usually use data-bind-html but this doesn't show in the input box.
Here is my string:
"Website Design & Development"
and currently my input field is as follows:
<input class="form-control" type="text" ng-model="group.name" required>
When I use mg-model, it populates the input form value fine, but when I use the following:
<input class="form-control" type="text" ng-bind-html="group.name" required>
Am I doing this correctly or can someone see where I am going wrong? I would ideally like a way to escape the html entities in the controller before it gets shown in the view but I am not sure if this is possible?
Thanks

<input type="email"> breaks ng-model data binding in modal dialog

My app uses a modal dialog with a simple input element
<input id="fieldEmail" class="form-control" type="text" ng-model="email" required="" />
email: {{ email }}
While the modal is being displayed, I can type something into the input field and see it echoed in the text beside it, as expected. But if I change the input type to type="email" it breaks the data-binding. Input is no longer echoed.
Has anyone else encountered this problem?
it will echoed only if input field has valid email.so put valid email in to input field and check it is working or not.this is because when type="email" ng-model only take valid email value,else it will undefined.
This is because of the type "email". Even if we use type='number', then also the 'ng-model' will be undefined unless you enter some valid number in the text box. For all the HTML5 input types we should give the valid inputs to assign value to ng-model.
And even when we use regular expressions for text boxes, the ng-model will be undefined until we give a value which satisfies the regular expression.
'http://plnkr.co/edit/G2RlzO4q1zKEPP0T8xvF?p=preview`
<body>
<h1>Hello Plunker!</h1>
Enter 3 to 12 characters only.
<br/>
<input type="text" ng-model="name" ng-pattern="/^[a-z]{3,12}$/"/>
<br/>
{{name}}

Resources