Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to match at least One capital letter and at least One digit and any number of special charecter

Hi I'm new to this regular expression. Please help me on this query.

I want the Regular expression to match at least One capital letter and at least One digit and any number of special characters. Minimum length 8 and maximum length can be 15.

Note : The special characters allowed are @#$&.

Thanks for your help.

like image 569
PaRsH Avatar asked May 17 '14 12:05

PaRsH


People also ask

How do you match a capital letter in regex?

Using character sets For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter.

What is the regex for special characters?

Special Regex Characters: These characters have special meaning in regex (to be discussed below): . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ . Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).

Which is the correct regular expression that password should contain at least one capital letter or one digit?

To check a password between 8 to 15 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character. To validate the said format we use the regular expression ^(?= .

What is the regular expression matching one or more specific characters?

The character + in a regular expression means "match the preceding character one or more times". For example A+ matches one or more of character A. The plus character, used in a regular expression, is called a Kleene plus .


1 Answers

Thanks guys. I found the answer.

/^(?=.*\d)(?=.*[A-Z])(?!.*[^a-zA-Z0-9@#$^+=])(.{8,15})$/
like image 54
PaRsH Avatar answered Nov 15 '22 16:11

PaRsH