开发者

ereg to preg conversion

I'm a com开发者_如何学运维plete novice when it comes to regex. Could someone help me convert the following expression to preg?

ereg('[a-zA-Z0-9]+[[:punct:]]+', $password)

An explanation to accompany any solution would be especially useful!!!!


To answer your real question, you'd need to structure your code like:

if ( preg_match( '/[a-z]+/', $password ) && 
  preg_match( '/[A-Z]+/', $password ) && 
  preg_match( '/[0-9]+/', $password ) && 
  preg_match( '/[[:punct:]]+/', $password ) ) ...

If you wanted to ensure the presence of at least one lowercase letter, at least one uppercase letter, at least one digit, and at least one punctuation character in your password.

Other questions you should read:

  • PHP regular expression for strong password validation
  • How do I measure the strength of a password?


preg_match('/[a-zA-Z0-9]+[[:punct:]]+/', $password)

You simply put a / at the beginning and a / at the end. Following the / at the end you can put some different options:

i - case insensitive

g - do a gloabl search

For more information in the beautiful world of regex in PHP, check out this:

http://www.regular-expressions.info/php.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜