I am trying to get this work for a while but in vain. I want to create a php regex to check if a string has atleast one number and atleast one of the symbols amongst ( _-+=*& )
This is my regex
$result = preg_match('/^(?=.*\d)(?=.*[_-+=*&]).{3,}$/',$pass);
I get the following error Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 17 in myfile.php on line 8
any help ?
The -
needs to be escaped, or placed at the start / end of the [...]
list:
$result = preg_match('/^(?=.*\d)(?=.*[-_+=*&]).{3,}$/',$pass);
If you don't, -
is interpreted as the range operator and if x > y
in [x-y]
you get that error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With