Solved

Regex for full name

Posted on 2010-11-11
9
593 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…

840 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