Solved

Regex for full name

Posted on 2010-11-11
9
588 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 11

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 11

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 74

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 74

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now