adammc
August 6, 2010, 3:29am
1
Hi guys,
can anyone possibly help me with this?
// Validate the product name
if(empty($product_name)){
$error .= "~ Please enter the product name.<br>";
}
if(!preg_match('/^[a-zA-Z\\'.-\\s]{2,30}$/',$product_name)){
$error .= "~ Invalid product name! (Only letters, spaces, apostrophes and hyphens are allowed)<br>";
}
The validation above wont accept apostrophes, what do I need to change?
Yes. You’re trying to validate (with the regex) user input, but you’ve already changed the input into something else entirely (with mysql_real_escape_string and stripslashes). (:
This works for me
<?php
$error = "Error: ";
$product_name = "Widgets G'lore you-bet";
if(!preg_match('/^[a-zA-Z\\'.-\\s]{2,30}$/',$product_name))
{
$error .= "~ Invalid product name! (Only letters, spaces, apostrophes and hyphens are allowed)<br>";
}
echo $error;
// output = Error:
?>
Are you sure it isn’t the 2 to 30?
Does the variable have escape slashes / enititized quotes it it?
adammc
August 6, 2010, 4:34am
4
I am using a cleaner function to guard against sql injection?
mysql_real_escape_string
stripslashes
Maybe this is causing me grief?