Solved

Regex for full name

Posted on 2010-11-11
9
596 Views
Last Modified: 2012-05-10
I need a regex for full name :

Only allow alpha numeric character (letter) and space.
0
Comment
Question by:softbless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 12

Accepted Solution

by:
tel2 earned 167 total points
ID: 34117218
Hi softbless.

Questions:
1. Does case (upper/lower) matter?
2. Is there a limit to the number of "words" it should match?

Think about names like:
    Joe de Guzman    (note "de" is all lower case, and there are 3 "words")
    Joe O'Gorman      (note quote and 3 uppercase chars)
0
 
LVL 5

Assisted Solution

by:chinawal
chinawal earned 84 total points
ID: 34117320
Depending up the where you are going to use RegEx, the RegEx pattern differ. However, the difference will be minor. There are numerous patterns.

Based on your requirement, this is the one :
^([a-zA-Z ']+)$


http://forums.devshed.com/regex-programming-147/full-name-string-match-556668.html
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 249 total points
ID: 34117337
Only allow alpha numeric character (letter) and space.
^[a-zA-Z0-9 ]*$
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Assisted Solution

by:tel2
tel2 earned 167 total points
ID: 34117602
Although the '*' should be changed to a '+', unless you're happy to accept names which contain nothing.
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 249 total points
ID: 34118089
Nothing satisfies "Only allow alpha numeric character (letter) and space."
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 249 total points
ID: 34118093
Btw, + still accepts names which contain only spaces.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34119841
>>  kaufmed , please make these clear :
>>  @" value=' . *'"
>>  why @ here?

I don't see where I used it, but the @ in front of a string literal turns the string into a raw string where backslashes are literal characters and not the escape character that they normally are.


Pattern explanation : ( ? < = I N P U T [ ^ > ] * ? v a l u e = [ \ " ' ] ? ) [ ^ \ " ' > ] *

(?<=  ...  )        Positive lookbehind; find this, but don't consider it part of the match
INPUT             literal
[^>]*?              zero or more ( * ) of any chacter NOT ( [^ ... ] ) a closing bracket  ( > ). Non-greedy ( ? ), so stop searching at the first match
value=             literal
["']?                  zero or one ( ? ) of either ( [ ... ] ) a single or double quote. Note, the backslash is an escape for the doble quote and not part of the pattern
[^"'>]*             zero or more ( * ) of any character NOT ( "[^ ... ] )  a single or double quote or a closing bracket. Again, the double quote is escaped
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34119871
Sorry, wrong post. I think my phone hates me. ; )
0
 

Author Closing Comment

by:softbless
ID: 34182919
thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question