Jump to content

allowing space in textfield


shakeit

Recommended Posts

Hello everybody, I have a little issue regarding chars and signs that are aprooved in a text string.

 

I want to check the field $name to contain only small and big letters which is usual in a name. But it happens that some people have two names, e.g. one main and one middle name. So I want to allow the user to write both names in one text field, i.e. by using space between them, for example: Jon Thomas. How do I add the space character in the code below in $goodChars, if it is possible?

 

Thanx very much in advance and I hope you understand the problem description :-)

 

----------------------------------------------------------------------------------

public function validateName($name)

{

 

$goodChars = "^[a-z_A-Z]+$";

 

if( ereg("$goodChars",$name) && strlen($name) > $nameLengthMIN )

{

 

return true;

 

}

else

{

return false; //Only A-E and -

}

 

}

---------------------------------------------------------------------

Link to comment
Share on other sites

You could simply add a space inside the square brackets. But I think you need to change it a bit, 'cause now a username could contain only an underscore (or more). Do you want an underscore to be allowed at all? If you want the name to either be pure a-zA-Z or a-zA-Z, then one underscore or space, and then a-zA-Z again, this regex would work (change ereg to eregi to make the check case insensitive):

 

^[a-z]+([ _][a-z]+)?$

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.