Forum Moderators: coopster
I am working on a form submission process and would like to check if a user has entered a valid name. By valid, I mean the name contains upper and lowercase letters, hyphens, spaces and apostrophes. I'm using this to validate the name feild:
if (!preg_match("/^[a-zA-Z'- ]+$/",$fullName) ¦¦ strlen($fullName) < 3 ¦¦ strlen($fullName) > 32) {
$invalidName = 1;
header("Location: login.php?invalidName=1");
}
This works for names like Bob Smith, or Ahmed Al-Mahdi, but will not work for names such as John O'Connor. The apostrophe returns the invalidName error. Any suggestions?
Thanks,
Max
From the warning you displayed, it seems that the problem is in the ordering of the characters but as I've said above, I've tried many different combinations and did not find a working solution. Any ideas?
Why is it causing the problems?
Try printing out the value of $fullname just before calling preg_match. Also add this at the top of your script:
error_reporting(E_ALL);
This will print out a warning if your regex is not properly constructed. Hope this helps.
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Reilly Al-M','Sam','69d5ae81a7af338d3a3ad366264b327f','What did you name your f' at line 3
I don't see any way around this!
Basically I have reCAPTCHA stuff on top followed by database connection code, then I define the variables
$email = addslashes($_POST['email']);
$fullName = $_POST['fullName'];
$username = $_POST['username'];
etc. etc.
then I have the :
if (!preg_match("/^[a-zA-Z'\- ]+$/",$fullName) ¦¦ strlen($fullName) < 3 ¦¦ strlen($fullName) > 32) {
$invalidName = 1;
header("Location: login.php?invalidName=1");
}
there is nothing else in here that should be interfering with the script but no matter what I try I can not get the database to accept a name such as John O'Connor. Everything else works great, I can get Billy Bob, or Mahmoud Al-Maliki, but that apostrophe just wont submit!
I know it's not the most secure way of going about it, but I'm just trying to get it working now and will worry about security after.