This question already has answers here:
Regex to validate password strength
(11 answers)
Closed 6 years ago.
Markup
<form ng-submit="doRegister(registerForm);" novalidate name="registerForm">
<input type="password" name="Password" ng-model="register.Password"
ng-pattern="/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/"/>
<span ng-show="registerForm.Password.$error.pattern" class="help-block">
min 1 lower char, 1 upper char, 1 digit and one special char
</span>
<button type="submit" ng-disabled="registerForm.$invalid" >
Submit
</button>
</form>
I am testing the Password Strength with min 1 lower char and 1 upper char and 1 digit and one special char
I am testing this string: a1A#s.com //Failed
I am testing this string:
12345aA! //Passed
Am I doing anything wrong?
It is failing because # is not part of your character class in last lookahead. You can also simplify your regex to this:
/^(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?=.*[#!$#%]).{3,}$/
RegEx Demo
Related
So I have this form that has an id input field.
I want to restrict it to alpha numeric with no spaces so I set this up:
self.pattern = /^[a-z0-9]*$/;
Which is used in my view like this:
<input class="form-control" name="id" type="text" ng-model="controller.model.id" ng-disabled="controller.id" ng-pattern="/^[a-z0-9]*$/" ng-trim="" ng-maxlength="10" required />
But I want to modify my pattern to say that there must be at least 1 letter, but it can have 0 digits.
Can someone let me know how to do this?
You may use
ng-pattern="/^\d*[a-z][a-z\d]*$/"
Add i modifier if you need to also match uppercase letters:
ng-pattern="/^\d*[a-z][a-z\d]*$/i"
If you need to disallow leading/trailing whitespaces add ng-trim="false".
Pattern details
^ - start of string
\d* - 0+ digits
[a-z] - a letter
[a-z\d]* - 0 or more letters or digits
$ - end of string.
Need ng-pattern for restricting entry of decimal in input type number.I have used
ng-pattern="/^[0-9]$/"
to get the result but its not showing error on 1.0,2.0,3.0 etc.
Example:
2.0 = fail
2 = pass
3.0=fail
3=pass
<div class="col-md-5 col-md-offset-7">
<input type="number" min="0" class="form-control" id="equalizingFactor"
name="equalizingFactor" ng-model="flatVariable.equalizingFactor"
itle="Equalizing Factor" ng-maxlength="3" ng-pattern="/^[0-9]$/"
message="The field should contain only numbers with no decimal places"
ng-readonly="flatVariable.pgmInd30"/>
</div>
Should only have numbers no decimals included.
These should work fine:
ng-pattern="/^[0-9]*$/" // 0 or more numbers
ng-pattern="/^[0-9]+$/" // 1 or more numbers
ng-pattern="/^\d*$/" // 0 or more numbers
ng-pattern="/^\d+$/" // 1 or more numbers
I want to do like this : 3.40 and not more than 3 characters and one dot:
<md-input-container class="md-block">
<label>Marks/CGPA</label>
<input type="text" name="education.cgpa" ng-model="education.cgpa"
ng-pattern="/^[0-9]{0,4}$/">
<div class="input-validation" ng-show="educationSaveForValidate['education.cgpa'].$error.pattern">
Insert valid CGPA
</div>
</md-input-container>
How can I allow only 3 digits and one dot in Regular Expression?
You may use a single regex like
ng-pattern="/^(?!.{5})\d*\.?\d+$/"
or - to allow an empty string:
ng-pattern="/^(?!.{5})\d*\.?\d*$/"
You may also move the length check out of the regex:
ng-pattern="/^\d*\.\d*$/" ng-maxlength="4"
Details
^ - start of string
(?!.{5}) - a negative lookahead that fails the match if there are any 5 chars in the input string
\d* - 0+ digits
\.? - an optional .
\d* - zero or more digits (if \d+ is used, then 1 or more digits)
$ - end of string.
To disallow any leading/trailing spaces, add ng-trim="false".
https://regex101.com/r/kF0hJ5/17
Check this link above, I hope it'll help you. Sorry for commenting link here. Doing so as I have less repo.
i have solved my problem this way......
ng-pattern="/^\d\.\d{0,2}$/"
<input ng-pattern="/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9])/" name="text" type="text" ng-model="formData">
From this I can check minimum 1 lowercase character, 1 uppercase character, 1 integer and 1 special symbol.
But I want to validate 2 lowercase characters, dynamically minimum numbers will change. So I have to write common validation.
How can I do this?
Can anyone help me. Thanks in advance.
use this for 2 lowercase, 2 uppercase, 2 integer, 2 special character
(?=.*[a-z]{1,2})(?=.*[A-Z]{2,2})(?=.*\d{2,2})(?=.*[^a-zA-Z0-9]{2,2})
try it here
I have this pattern like so
<input name="ip" ng-pattern="/^http:\/\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]{4,5}/" class="form-control full-width text-right" type="text" ng-model="resource.ip"/>
The last part {4,5} is at least 4 and no more than 5. But when I type more than 5 integers at the end the form doesn't change to ng-invalid
This works on http://www.regexr.com/
Any idea why my input is allowing more than 5 characters?
Just add $ to define the match end.
^http:\/\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]{4,5}$
From the Reference > Archors > end:
Matches the end of the string, or the end of a line if the multiline flag (m) is enabled. This matches a position, not a character.