Current time: 07-22-2014, 07:28 PM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex to test a person's Full name
06-26-2007, 01:24 AM
Post: #1
Regex to test a person's Full name
What I'm looking for is a regular expression to test a person's full name to make sure the input isn't an attempt at XSS or SQL injection but I haven't founf such an expression. Does anyone have one that I can use?

Examples:

John Wayne <- True

[Image: bannersimcity4bn.jpg]
Find all posts by this user
Quote this message in a reply
06-26-2007, 04:07 PM (This post was last modified: 06-26-2007 04:10 PM by Asad_Niazi.)
Post: #2
RE: Regex to test a person's Full name
Full Names can contain upper/lower alphabets, spaces, and dots. So I guess it's pretty simple, try this:
PHP Code:
$fullName 'John Wayne';
$fullName trim($fullName);
if (
preg_match('#^[a-z\s\.]+$#i'$fullName)) {
     
// it's all good
} else {
     
// it's all bad


Or you can add minimum and max limits of characters as well:
^[a-z\s\.]{4,40}$

You can add it to a function/method if you've to re-use it in many parts of the program.

Linux Server overloading explained
Move MySQL to a second drive
Visit this user's website Find all posts by this user
Quote this message in a reply
06-26-2007, 05:16 PM
Post: #3
RE: Regex to test a person's Full name
Okay Thanks Asad.

[Image: bannersimcity4bn.jpg]
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication