I have the following as a validation check on a search field,
The person entries a name between 3 - 12 characters long and the function checks to see if it's only a string of letter and everything works fine.
Now however I need to add in a single quote " ' " I've tried every combination I can think of and none of them work my best guess was [^a-zA-Z'] but that did not work and I've tried tons but get no where... help
Peter
original code:
function is_alpha($someString) //function to check for letters
{
return (preg_match("/[^a-zA-Z]/", $someString) > 0) ? true : false;
}
$element = $_POST['name'];
if (strlen($element) <3 or strlen($element) >12)// check letters entered is between 3-12
{
header("location:searchform.php?err=1"); // return error call
}
if(is_alpha($element)) //check that only letters entered
{
header("location:searchform.php?err=2"); // return error call
}




Reply With Quote

Bookmarks