Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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?


John Wayne <- True
[Image: bannersimcity4bn.jpg]
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:

You can add it to a function/method if you've to re-use it in many parts of the program.
Okay Thanks Asad.
[Image: bannersimcity4bn.jpg]

Forum Jump:

Users browsing this thread: 1 Guest(s)