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:
- Any lower/upper case letter
- Any digit
- Can contain spaces
- Cannot contain line breaks or tab space
- Minimum of 7 characters
- Maximum of 30 characters
Valid inputs:
- Testing
- Test ing
- Test123
- Test 123
- Test___
Invalid inputs:
- Testing#
- Testin8+
- Tester1&
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.