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
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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.