Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-26-2006, 03:51 PM   PM User | #1
fogofogo
New Coder

 
Join Date: Sep 2005
Posts: 89
Thanks: 2
Thanked 0 Times in 0 Posts
fogofogo is an unknown quantity at this point
form validation

Hello all - probably a simple one, but not for me!

I'm trying to check if a variable from a form has any spaces in it. I don't want to strip out the whitespace (as its a username and password), but display a warning.

Heres what I have so far:

if( !eregi("^[a-z0-9]+)*",
$_POST ['nickname'])){
readfile("blankfields.html");
exit;
} else {
}

Any suggestions?

Thanks
fogofogo is offline   Reply With Quote
Old 04-26-2006, 03:53 PM   PM User | #2
MRMAN
Regular Coder

 
Join Date: Jan 2006
Location: Preston, Lancashire, England
Posts: 285
Thanks: 0
Thanked 0 Times in 0 Posts
MRMAN is an unknown quantity at this point
simplest way would be this
PHP Code:
$username str_replace(" """,$_POST['nickname']) 
MRMAN is offline   Reply With Quote
Old 04-26-2006, 04:54 PM   PM User | #3
fogofogo
New Coder

 
Join Date: Sep 2005
Posts: 89
Thanks: 2
Thanked 0 Times in 0 Posts
fogofogo is an unknown quantity at this point
Quote:
Originally Posted by MRMAN
simplest way would be this
PHP Code:
$username str_replace(" """,$_POST['nickname']) 
Thanks MRMAN.

I actually can't strip out the gaps, as its going to be the users name and password. If i strip it out, then their log in will be different. (for example: the user inputs 'player 1', and the application saves it as 'player1')

I have put a notice on the form asking users not to add spaces but they are not reading it. So I need to check it and issue a warning if there is a space.
fogofogo is offline   Reply With Quote
Old 04-26-2006, 05:01 PM   PM User | #4
fogofogo
New Coder

 
Join Date: Sep 2005
Posts: 89
Thanks: 2
Thanked 0 Times in 0 Posts
fogofogo is an unknown quantity at this point
actually I just got a fix for it.

If anyone is interested:

if ( substr_count ($string, " ") > 0 ) {

// We have spaces

} else {

// We don't

}


Thanks
fogofogo is offline   Reply With Quote
Old 04-26-2006, 06:51 PM   PM User | #5
trib4lmaniac
Regular Coder

 
trib4lmaniac's Avatar
 
Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
trib4lmaniac is an unknown quantity at this point
You'll usually find that sitepoint gets your answers to your questions a little quicker than around here.
Although I'm happy to answer your questions anywhere
trib4lmaniac is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:13 AM.


Advertisement
Log in to turn off these ads.