working with ereg to refuse empty spaces

A

Anonymous

Guest
Hello ,

I use this code to check what entered on my $name webform

Code:
if (strlen ($name) < 1 || strlen ($name) > 20 || !ereg ("[a-z0-9]", $name)) { 
$error = "Please check name entered";
}
else $error = "";

however if in the webform I insert an empty space (" ") and click enter , the code above doesn't report any error .... What I have to do to avoid that the empty space(s) in the webform will be accepted (such as a caracther ).

For example this " " or this " " must not be accepted .
While "Mr John" should be accepted ...

Anyone may help to correct the code above ?
Thanks
 
leon said:
Hello ,

I use this code to check what entered on my $name webform

Code:
if (strlen ($name) < 1 || strlen ($name) > 20 || !ereg ("[a-z0-9]", $name)) { 
$error = "Please check name entered";
}
else $error = "";

however if in the webform I insert an empty space (" ") and click enter , the code above doesn't report any error .... What I have to do to avoid that the empty space(s) in the webform will be accepted (such as a caracther ).

For example this " " or this " " must not be accepted .
While "Mr John" should be accepted ...

Anyone may help to correct the code above ?
Thanks

Sorry it seems working now . :oops:
 
Use the trim function if you run into problems again

do something like
$name = trim($name);
 
Back
Top