Thursday 19 May 2022

PHP Regex Sample Code


A regular expression (shortened as regex or regexp or rational expression) is a sequence of characters that specifies a search pattern in the text.

A good testing site is 

https://infoheap.com/php-preg_match-online/ 

Examples of regex for password

PHP Version

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


Must have special characters

(?=\S*[\W])


Must have a number

(?=.*\\d)


Must have uppercase and lowercase

(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z])


Some reference

https://stackoverflow.com/questions/8141125/regex-for-password-php

https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a

Share:

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.