You're trying to print an integer, which won't achieve what you're trying to do. Try this:
if( preg_match( "/^[a-z0-9@!?_;:,.]{4,12}$/i", $test_string )) {
echo 'valid string!';
} else {
echo 'invalid!';
}
Note that your regex deems strings to be valid if they are:
- Between 4 and 12 characters long
- Consist of only alpabetic characters, numbers, and the other characters you've included.
Also note that your input string is supposed to be invalid, not only because it is too long, but because it contains a dash, which is not supported by your regex:
1234bcd@!?_;:-,.
^
No match
To include it in your regex, place it at the end of your character class in the regex:
preg_match( "/^[a-z0-9@!?_;:,.-]{4,12}$/i", $test_string )
^
0, as your$test_stringis too long: the pattern will match only if the tested string's length is between 4 and 12.