Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex to test a person's Full name
#1
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]
Reply
#2
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.
Reply
#3
Okay Thanks Asad.
[Image: bannersimcity4bn.jpg]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)