Hi everybody.
I'm having a problem with preg_match function.
I have a field where I want to allow only letter or numbers, but no spaces or any special characters (field is for login name).
I'm using a preg_match for it that look like this:
function validateTextOnlyNoSpaces($theinput, $description = ''){
$result = preg_match ("/^[A-Za-z0-9]/", $theinput );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}
}
after I'm calling it like this
$name = $_POST['n_user'];
$theValidator->validateTextOnlyNoSpaces($name, 'User login cannot contain spaces');
but the function returns error "no spaces allowed" even when there are no spaces in the name.
Anybody knows what's wrong in my function.
Thanks.