lewis1682 Posted November 25, 2013 Share Posted November 25, 2013 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 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 25, 2013 Share Posted November 25, 2013 Better of splitting the names into multiple fields. Such as First name, Middle name(s) and Last name fields. Then validate each field separately. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 25, 2013 Share Posted November 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.