Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for 1 uppercase 1 special character and 1 lowercase [duplicate]

Tags:

regex

I need a regex for 1 uppercase 1 special character and 1 lowercase Note need to allow all special character and it should be above 8 character in length.

I have tried /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/ this but this is restricting some special character.

like image 700
Ashwin Avatar asked Nov 12 '15 11:11

Ashwin


2 Answers

Try to use this regex:

^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+*!=]).*$

REGEX DEMO

Explanation:

(/^
(?=.{8,})                //should be 8 characters or more
(?=.*[a-z])             //should contain at least one lower case
(?=.*[A-Z])             //should contain at least one upper case
(?=.*[@#$%^&+*!=])      //should contain at least 1 special characters
.*$/)
like image 195
Rahul Tripathi Avatar answered Oct 14 '22 14:10

Rahul Tripathi


I would use:

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

Note that [^\w\d] allow any special char.

like image 22
Thomas Ayoub Avatar answered Oct 14 '22 13:10

Thomas Ayoub