Here is the regex I currently have (which kind of works):
$regex = '/[\w ]{7,30}/';
My revision looks like what I want, but it does not work at all:
$regex = '^[\w ]{7,30}$';
Here is how I am using the regex:
public function isValid( $value )
{
$regex = '/^[\w ]{7,30}$/';
return preg_match( $regex, $value ) ? true : false;
}
I am trying to match the following:
Valid inputs:
Invalid inputs:
The first regex will match all valid inputs, as well as invalid (as long as the first four characters are valid, it doesn't care about the rest). The second regex matches nothing.
Try combining both like so:
$regex = '/^[\w ]{7,30}$/';
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