Regular expression to match 6-15 alphanumeric characters plus characters above 1-8 keys on the keyboard

I am trying to get a regular expression that allows between 6 - 15 characters and can be a-zA-Z0-9 and the characters above the numbers 1 - 8 on the keyboard.

Here is what I have, but it does not work.

'/^[a-zA-Z0-9-_][\!\@\#\$\%\^&\*]{5,16}+$/' 
+7
regex
source share
4 answers

you have two different sets in brackets. Basically the expression says "1 of a-zA-Z0-9-_", followed by 5-16 special characters. Combine them into the same set of brackets, and you are fine.

Something like the following:

 '/^[a-zA-Z0-9-_\!\@\#\$\%\^&\*]{5,16}$/' 
+15
source share

Try the following:

 ^[\w-!@#$%^&*]{6,15}$ 

How \w means [a-zA-Z_0-9]

0
source share
 '/^[a-zA-Z0-9-_!@#$%^&*]{5,16}$/' 
0
source share
 /^[\w\!\@\#\$\%\^&\]{6,15}$/ 

This is what would be in Perl.

0
source share

All Articles