MyBB Community Forums

Full Version: Regex to test a person's Full name
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Full Names can contain upper/lower alphabets, spaces, and dots. So I guess it's pretty simple, try this:
$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.
Okay Thanks Asad.