Reply
ereg() for first and last names
Old 04-04-2008, 01:33 PM ereg() for first and last names
Super Talker

Posts: 119
I'm trying to validate first and last names, but everything I try it seems to accept. If I input KYle, it accepts it, Kyle, accepts it, but KYLE doesn't accept it. Hopefully someone can show me what I'm doing wrong...

Code:
ereg("([A-Z]{1})([a-z])", $name)
I thought this would accept the first digit as uppercase, then the rest being lowercase.

And this is a very generic check...there isn't anything in there for more unique names with dashes in it and stuff like that. I've tried googling help with ereg, but all the places I find just show examples and not how they act, nor really how to create your own custom ereg() function.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-04-2008, 04:02 PM Re: ereg() for first and last names
Average Talker

Posts: 15
Perhaps the problem is that your pattern would match a capitalized letter followed by a lowercase letter anywhere in the string, which is why "KYle" would pass. Try making it go from the beginning of the line:
"^([A-Z]{1})([a-z])"Which should only be true if the first letter of the string is capitalized.

You could also explode the string on ' ' (space) and then run the pattern against each part of the name...
__________________
30 Day Money-Back Guarantee - PHP Hosting - VPS Hosting - Linux Dedicated Servers
awatson is offline
Reply With Quote
View Public Profile
 
Old 04-05-2008, 12:37 AM Re: ereg() for first and last names
Ultra Talker

Posts: 308
Like awatson said, this regex will match any part of the string containing uppercase letter followed by lowercase letter. I don't know why you're even bothering with case of the letter, just check if the length is correct or not and if it contains any character you don't want in a name. You can always capitalize the first letter in names by using either ucfirst and ucwords function.
__________________
tiny url
dman_2007 is offline
Reply With Quote
View Public Profile Visit dman_2007's homepage!
 
Old 04-05-2008, 04:28 AM Re: ereg() for first and last names
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 950
Name: Jeremy Miller
Location: Reno, NV
The advice of the other 2 posters is accurate. Let me suggest that you don't want to do this. What if my last name was MacArthur? People are WAY too creative with name for anything but a length > 2 or 3 characters validation.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 04-05-2008, 05:31 PM Re: ereg() for first and last names
rogem002's Avatar
Webmaster Talker

Posts: 567
Name: Mike
Location: United Kingdom
Quote:
Originally Posted by JeremyMiller View Post
The advice of the other 2 posters is accurate. Let me suggest that you don't want to do this. What if my last name was MacArthur? People are WAY too creative with name for anything but a length > 2 or 3 characters validation.
Makes a good point. I think the best thing to do is let lowercase and uppercase through, but not numbers. Though then again some people have numbers in there name as well, for example "Number 1" or "MacLovin The 3rd".
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);} 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-05-2008, 06:12 PM Re: ereg() for first and last names
Super Talker

Posts: 119
You make some valid points. I guess I'll just make sure it's only letters, and no numbers or other characters. The check is from a form for adding a new employee, so only a manager will be doing it and they shouldn't really need to try and break it. Thanks for the input guys, really helps!
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ereg() for first and last names
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12825 seconds with 13 queries