简体   繁体   中英

php - preg_match: minimum char count ignored

This is my regex test

if (preg_match("/^[a-z0-9\.]{5,25}$/", $reg_username) === false) {
            echo "Testing failed <BR>";
}

If $reg_username is real , the test pass, but I've specified that I need a minimum of 5 chars. What am I doing wrong?

I tested the regexp on a online tester and it fails in this case.

You just failed on reading manual.

false will be returned on error, but if string doesn't match you'll receive 0 .

Check it out carefully

if (!(preg_match("/^[a-z0-9\.]{5,25}$/", $reg_username))) {
            echo "Testing failed <BR>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM