Jump to content

Regex for a simple password


linus72982

Recommended Posts

I am building a new site for forums that has a high population of old people and they wouldn't appreciate me not allowing their simple passwords, so I search and search and everything I found on google requires complexity.  So, if anyone can help with a regex that does the following, I'd appreciate it:

 

1. Can contain only letters, numbers, and symbols (just the normal symbols, no unicode or slashes, etc)

2. Cannot contain spaces

3. Must be 8-16 characters in length

 

That's it, no other complexity required.  Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/229623-regex-for-a-simple-password/
Share on other sites

Well, since you didn't really fully define what you consider to be "normal" symbols, this regex will only accept letters, numbers and any of the symbols above the numbers on your keyboard.

 

if (preg_match('~^[a-z0-9!@#\$%\^&\*\(\)]{8,16}$~i',$password)) {
  // valid
} else {
  // invalid
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.