Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 177
Trades: 0
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
 
 
Register now for full access!
Old 04-04-2008, 04:02 PM Re: ereg() for first and last names
Average Talker

Posts: 18
Trades: 0
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 -
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

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: 310
Trades: 0
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.
dman_2007 is offline
Reply With Quote
View Public Profile
 
Old 04-05-2008, 04:28 AM Re: ereg() for first and last names
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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

Please login or register to view this content. Registration is FREE
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
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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".
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
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
Extreme Talker

Posts: 177
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.24452 seconds with 12 queries