简体   繁体   中英

What is the format for pattern String in pattern Attribute?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM