Jump to content

Expected string for form validation


lewis1682

Recommended Posts

Hey, I have created a contact us form which works nicely with my site, however I have some backup PHP validation code, which all works apart from the last name section, how can I set it up to it checks to see if there is a first name and a last, maybe even another name? This is what I have so far and it only works if you put in a first name and nothing else:

	$string_exp = "/^[A-Za-z.'-]+\$/";
	if(!preg_match($string_exp, $name)) {
		$error_message .= 'The Name you entered does not appear to be valid.<br/>';
	}

Thank you

Link to comment
Share on other sites

Kind of hard for us to provide any real help without knowing where the first name and last name are defined. All I see is a variable called $name. Are you concatenating the first and last name fields before doing the validation?

 

Also, I would ask why you care what data is in the name fields? Do you realize that you would potentially restrict valid names? For example, what about letters with accents such as "Muñoz". It gets even more complicated when dealing with character sets that are not Latin based. Now, there could be valid reasons to limit the valid characters in the name fields. But, if you don't have a valid business reason for doing so, it is not worth the effort - in my opinion.

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.