OldWest Posted January 7, 2011 Share Posted January 7, 2011 I've been cracking at this for the part of 2 days now, and I cannot get my regex to work properly in my script. /^[A-Za-z][\w\-',.]*(?<![^A-Za-z][\w\-\'\,\.])$/i The above is for a last name field, and it needs to be able to accept: Roberts, Jr. (as an example)... As you can see in my regex, I am allowing all of these characters.. And it's still not validating it. You can test to see what I mean here: <?php $last_name = "Roberts, Jr."; if (!preg_match("/^[A-Za-z][\w\-',.]*(?<![^A-Za-z][\w\-\'\,\.])$/i", $last_name )) { echo "Sorry no dice!"; } ?> Link to comment https://forums.phpfreaks.com/topic/223703-preg_match-regex-for-first-name-and-last-name-in-separate-fields/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.