Good community!
I have the following doubt. How can I warn the user that there are white spaces in the username
field?
Here's how I'm validating username
now:
if (empty($_POST["username"])) {
$nameErr = "Escolha um username.";
} else {
$uname = test_input($_POST["username"]);
$v1='ok';
if (!preg_match("/^[a-zA-Z-0-9-_]*$/",$uname)) {
$nameErr = "Somente letras e números.";
}
}
The solution was this:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["username"])) {
$nameErr = "Escolha um username.";
} else {
$uname = test_input($_POST["username"]);
// check if name only contains letters and whitespace
// aqui
if (!ereg("(^[a-zA-Z0-9]+([a-zA-Z\_0-9\.-]*))$", $_POST["username"]) ) {
$nameErr = "Somente letras e números.";
}
}