How do you check if a string contains invalid characters?
I want to restrict each user's username with PHP to having numbers, letters, and underscores.
You can use a regular expression:
if (preg_match("^[0-9A-Za-z_]+$", username) == 0) {
echo "<p>Invalid username</p>";
}
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