I'm trying to validate a password with PHP and I want to use the same Regex with Javascript, In my PHP I'm getting error when I'm trying to use the following regex.(Warning: filter_var(): Compilation failed: range out of order in character class at offset 14)
/^[a-zA-Z0-9_-\]\[\?\/<~#`!@\$%\^&\*\(\)\+=\}\|:\";\',>\{]{4,20}$/
if (!filter_var($password,FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z0-9_-\]\[\?\/<~#`!@\$%\^&\*\(\)\+=\}\|:\";\',>\{]{4,20}$/")))){
$errors .= "Please enter a valid password.";
}
I want the password to have 0-9,a-zA-Z and these characters ] [ ? / < ~ # ! @ $ % ^ & * ( ) + = } | : " ; ' , > { space plus `
I want to use the regex for front and back ends.
password_hash()compatibility pack.$password = password_hash($user_passwd, PASSWORD_DEFAULT);^[a-zA-Z0-9_\]\[?\/<~#`!@$%^&*()+=}|:\";\',>{ -]{4,20}$. I see your regex is missing a space, I added it, too. However, the hyphen is missing from your list of allowed characters. Something does not click here.