How to make a password include at least one special character? - angularjs

The password field should be more than 8 characters and include at least one special characters. How to meet the 'at least one special character' requirement in AngularJS?
<input type="password" name="pwd" data-ng-minlength="8" data-ng-model="user.pwd" />
How to add password validation using regular expression in angularjs according to certain criterion?
This question is very helpful to me, but my password requirement is slightly difference, like no number is allowed in my password, and I want to seperate the length requirement and special character requirement if possible so I can tell users what is the exact error. And I just wonder where can I learn how to set up ng-pattern? For me, they look like random characters...like this one:
ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$#$!%*#?&])[A-Za-z\d$#$!%*#?&]{8,}$/"

You can do this easily with below code
var regularExpression = /^(?=.*[0-9])(?=.*[!##$%^&*])[a-zA-Z0-9!##$%^&*]{6,16}$/;
With the above regex you can complete your task, for detail study of it go to the link :
https://www.w3schools.com/Jsref/jsref_obj_regexp.asp

Related

Parsley.js Validation Requirement

Good afternoon all! I am looking for some guidance to see if this type of validation is possible. I work for a college and am using a form that pushes to our CRM when complete. I am looking for parsley to only validate the email address field IF they enter their college email address. Is this possible? I am trying to weave out personal email accounts and keep everything uniform with the same email address.
Thanks in advance!
You can do that e.g. by using data-parsley-pattern and defining a pattern that matches only the required mail addresses. The pattern to validate against the mail addresses you mentioned in your comment might look like this:
.*#(mail\.)?walshcollege.edu$
This matches everything that:
Starts with any number (*) of arbitrary characters (.)
Followed by an #
Might be followed by "mail.". The dot is escaped to avoid the special meaning "any character", the question mark means "might be there or not" and the parentheses make the question apply to the complete string.
Ends with walscollege.edu (the $ means the end of the string)
If you also want to make sure that an mail address is inserted you need to add data-parsley-required as Parsley by default does not validate empty fields.
Also keep in mind that Parsley validation is only client side, so you should add validations in the server to really make sure that no wrong mail address is used.

Custom ng pattern expression for custom email

I want to validate an email for only certain type of kind. So I know that I need to use ng-pattern expression to make custom validation. I went through the Angular docs but I could not understand how to use it.
The solution I am looking for is something like, for instance, I want users to only use "anychar mix with num #gmail.com" for email when registering.
A try that I have thought of but i know this is not good. I have fixed after the #gmail.com which will match but how to do before of the mix of chars or numbers?
My test sample:
var pattern = '[a-z][0-9]+\#+gmail+\.+com';
<input ng-pattern="pattern"/>
Can you kindly guide me on this one?
Thank you !
This is the best pattern to check valid email address:
ng-pattern='/^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
You can try this another regex:
ng-pattern='/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}#)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*#(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/';

Can you test foreign language strings like Arabic or Russian?

My website has the ability to be viewed in different languages. Is it possible to use sendKeys with a var that looks like this:
var arabic = "صباح الخير
I have tried using:
element(by.css(...)).sendKeys(arabic);
however question marks are the only characters sent to the text box.
Is this possible?
From Protractor point of view, if you see only ??? in input or whatever you are filling the extended chars in, it is probably a bug in that webpage, because generally sendKeys('باح الخير') works absolutely fine.
By the way, silly question, but have you tried pasting those extended chars to input directly, without protractor?

angular no spaces form validation

How would you in angular validate for that a text box has no spaces. Is there a built in expression or would I have to fall back on a regular expression?
For example I would like if a user types in the following into a text input field
Pass/valid:adf
Fail/Dirty:a s d
Yes, you would need a pattern. Required is just going to make sure something is in there. I'm sure you've looked at it but for others, Angular docs show the available input validation options:
http://docs.angularjs.org/api/ng/directive/input
what about this:
ng-pattern="/^\s*\w*\s*$/"
this regex evaluates for spaces inside the input

AngularJs Search functionality is not working when more than one special characters

I have implemented Angular Js search functionality in application. When I have enter more than one special characters for example '!#' it will display all the results.I think the exclamation character is the problem. How can I resolve this? In their demo site is also not working.http://docs.angularjs.org/api/ng.filter:filter
source can find from their site.
See you are working somewhat wrong, because it allows you to have the multiple special characters search, but in your case you are using "!#" it means not include all those result having "#" in it.
So, if you choose to have "#*" it will show you to get all the result having these characters together.

Resources