working with ereg to refuse empty spaces

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
leon
New php-forum User
New php-forum User
Posts: 36
Joined: Sat Aug 03, 2002 11:54 am

working with ereg to refuse empty spaces

Postby leon » Tue Nov 05, 2002 10:58 am

Hello ,

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

Code: Select all

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

User avatar
leon
New php-forum User
New php-forum User
Posts: 36
Joined: Sat Aug 03, 2002 11:54 am

Re: working with ereg to refuse empty spaces

Postby leon » Tue Nov 05, 2002 11:00 am

leon wrote:Hello ,

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

Code: Select all

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:

DutchBen
New php-forum User
New php-forum User
Posts: 36
Joined: Thu Oct 24, 2002 10:28 am
Location: Amsterdam

Postby DutchBen » Wed Nov 06, 2002 12:37 pm

Use the trim function if you run into problems again

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


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 4 guests

cron