Checking the form for spaces and Russian letters

Hello, please tell me if there are any functions and which ones can check the presence of spaces and Russian letters in php. For example, you need to write a login and it should consist only of Latin characters, excluding spaces, Russian letters, all sorts of dots and commas. Maybe even with ajax?


Answer 1, authority 100%

You need to check some form data regularly, for example for a password:

$preg = '/[a-zA-Z_0-9]+/';
$check = preg_match($preg, $_POST['password']);
if($check == true) {
    //true       
    //.,    
}
else {
    //    false
}

This is a check on the server, everything is done in the same way on the client:

var password = document.getElementById("password").value; //  
var passwordPreg = /[a-zA-Z_0-9]/; // ...
if(passwordPreg.test(password) === true) {
    // 
}
else {
   // ...
}

It is important to understand that checking on the client is not enough and it is done only for the convenience of users, i. even having implemented a check on the client, any data must be rechecked by the server.
Naturally, you can write a validating script on the server and ask it with Ajax, but validation written on the client works faster (which is actually logical)


Answer 2, authority 50%

if (preg_match('/^([a-z]|\d|_)+$/i', $_POST['password'])) {
//  ,       ,   .
} else {
//   
}

Answer 3

Invalid regular expression. For example, qwerty123will be TRUEbecause preg_matchwill match qwerty123

in the string