I'm coding a site that has a registration page, in which users need to choose a username and password. These fields can only contain the following characters:
A-Z,a-z,0-9, and "_"
Any other characters in these fields, including the " " (space character), single or double quotes, or any other invalid character needs to return an error.
On my registration page, I have the following setup:
function check_chars($string) {
if (valid) {
return true;
} else {
return false;
}
}
// code
if (!$check_chars($username)) {
// error handling
}
if (!$check_chars($password)) {
// error handling
}
I just need the check_chars function. Can someone provide a reliable function to do this, or point me in the right direction? I'd rather not spend hours coding and testing this function if someone else has already written something =)
TIA,
Daren Cotter