Solved

Regex for full name

Posted on 2010-11-11
9
591 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question for a Awk & Sed Blackbelt 5 50
Powershell regex followup 13 74
Powershell String Parsing with Regular Expression 19 39
Allow space in this pattern 2 48
by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now