0

I want to have a password or form pattern defined by myself but I can't find in Internet how to do that customized ones.

I know there are ng-pattern in angularJs and pattern attribute in HTML but my problem is what is the format for that and what does '{ }', '[ ]', '/' mean? And how to set AND, OR conditions in that?

Can someone help me with this?

Ranger
  • 129
  • 2
  • 11

2 Answers2

0

You can use pattern attribute in HTML and define your custom pattern in it.

See below:

<input type="password" id="password" name="password" placeholder="password"
pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}" required="required" />

This pattern will have a check that password contains lowercase, uppercase, special character and numeric value.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1) Why Did you started with '^' ? 2) what is (?=.*\d) in the middle? 3) I want my password to start with 'A' so what should I include? – Ranger Feb 22 '17 at 03:50
  • you need to learn regex usage first if you are not familiar with. ^ will matches starting a string. ? will match zero or one occurrences of the preceding element. * matches zero or more occurrences of the preceding element. (.) matches any single character – Vinnod Kumar Kashyap Feb 22 '17 at 04:12
0

Try this

ng-pattern="/^([A_])+(([\._\-\~\=\+\?\*\@])*([a-zA-Z0-9])*)*$/"

[A_]- This checks that your pattern starting with Alphabet A.

  • / -> Charachters delimit the regular expression

  • ^ -> Match at the beginning of the line

  • . followed by * -> Match any character (.), any number of times (*)

  • $ -> End of the line

limsha
  • 128
  • 6