Just another WordPress.com site

Regex in PHP

1. 1 Character 1 number and string length

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

  • ^: anchored to beginning of string
  • \S*: any set of characters
  • (?=\S{8,}): of at least length 8
  • (?=\S*[a-z]): containing at least one lowercase letter
  • (?=\S*[A-Z]): and at least one uppercase letter
  • (?=\S*[\d]): and at least one number
  • $: anchored to the end of the string

To include special characters, just add (?=\S*[\W]), which is non-word characters

OR

(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$

   * contain at least (1) upper case letter
* contain at least (1) lower case letter
* contain at least (1) number or special character
* contain at least (8) characters in length

References
1. http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm
2. http://www.regular-expressions.info/index.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: