I need to check to see if a variable contains anything OTHER than a-z A-Z 0-9 and the "." character (full stop). Any help would be appreciated.
There are two ways of doing it.
Tell whether the variable contains any one character not in the allowed ranges. This is achieved by using a negative character class [^...]:
preg_match('/[^a-zA-Z0-9\.]/', $your_variable);
Th other alternative is to make sure that every character in the string is in the allowed range:
!preg_match('/^[a-zA-Z0-9\.]*$/', $your_variable);
if (preg_match('/[^A-Z\d.]/i', $var))
print $var;
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