...

View Full Version : form validation



fogofogo
04-26-2006, 04:51 PM
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

MRMAN
04-26-2006, 04:53 PM
simplest way would be this


$username = str_replace(" ", "",$_POST['nickname'])

fogofogo
04-26-2006, 05:54 PM
simplest way would be this


$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
04-26-2006, 06:01 PM
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

trib4lmaniac
04-26-2006, 07:51 PM
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 :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum