phpregexvalidationpasswordspassword-strength

Validate that a submitted password contains the required minimum strength


I'm getting a very uninformative REG_BADRPT error on the following line:

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

Can anyone see what the problem is?

I've used the same regex in Javascript and it works fine so not sure what the problem is here.

What I'm trying to achieve here is set a regex that would validate strings that contain:


Solution

  • Well I ended up changing the regex with this one and it works fine:

    if(preg_match("#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$#", $_POST['password']))
    

    Stil dont know what the problem was before