Regular Expression

Asked

Viewed 157 times

1

Regular Expression for password validation. I want it to be possible at least a minuscule letter, a capital letter, at least a number and special characters (/,_,-, ... ). Example: $regex = '#^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$#';

How can I add more special characters?

2 answers

6


In the minimum 8 letters, at least one Maíscula, at least one Lowercase, at least 1 Number and accepting special:

^(?=.*[a-zç])(?=.*[A-ZÇ])(?=.*\d)[\S\s]{8,}$

Here is a link to tests EXTERNAL.

  • Thank you for your reply, but I do not want to oblige you to have a minimum of special characters.

  • Now you can have as many specials as you want, including none.

  • @akm I think I finally understood your need and updated the response with external link, improved?

  • cool! (+1) ^(?=.*[a-zç])(?=.*[A-ZÇ])(?=.*\d).{8,}$

2

You already have almost all of it, just change the ending:

#^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d_ /.-]{8,}$#.

Remembering that \w is a summary for [a-zA-Z0-9_].

Thus remaining :

#^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\w /.-]{8,}$#.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.