Quote:
Originally Posted by pbmods
You'll probably want something like this:
-
preg_match('/^[\d]+(\/[\d]+)?(\b\w)+$/', $value4);
-
That would most closely match '10/54 kent street'.
The regular expression there matches at least one number, then optionally (a slash followed by at least one number), then at least one word.
If you want to be able to do something like '10/54 west 3rd street', you'll have to modify it slightly (assumes that street names only start with numbers and never have numbers in the middle or end):
-
preg_match('/^[\d]+(\/[\d]+)?(\b\d*\w)+$/', $value4);
-
For more info:
http://www.regular-expressions.info/reference.html I tried that script but it didnt do the trick, thanks for it though maybe I needed to twist and turn a little bit to make it suitable for my use. I managed to use the script that i had made before but however I have encountered and even bigger problem and it is as follows:
Could someone please help me with my regular expresssions because my script is behaving in a rather wierd way when I implement the regular expressions. I am checking names and addresses before I insert them into my database but the regular expression function is not working when the MYSQL INSERT QUERIES are running. Below is my script and I'm just going to briefly explain it. The isWord($value,$pageURL) funtion is in a file called dbFunction.php and its as follows:
-
function isWord($value,$pageURL){
-
$value2 = trim(stripslashes($value));
-
f((strlen($value2) == 0) or (!ereg("^[[:alpha:]'-]{1,100}$",$value2))){
-
$uri = "//" . $_SERVER["SERVER_NAME"]. rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
-
header("Location: http:".$uri.$pageURL."&err=1");
-
}else{
-
return $value2;
-
}
-
}
[Please use CODE tags when posting source code. Thanks! --pbmods]
I then called it in dbJobsheet as follows:
-
$firstName = isWord($_POST['firstName'],$errorPageURL);
this works perfectly because if I put in invalid characters I get redirected to the error page. However when I put in the script to insert the data into the database the above isWord($value,$pageURL) doesnt work.
the script that stops all this from working is as follows:
- <?
-
$timeQuery = mysql_query("SELECT date_assinged,time_assigned,assStaffID
-
-
FROM FOLLOW_UP WHERE
-
time_assigned ='$newTime' AND
-
date_assinged = '$newAssignedDate'
-
AND assStaffID = '$assStaffID' ")
-
or die(mysql_error());
-
-
$results = mysql_fetch_array($timeQuery);
-
//checks if there is a time clash and redirects user to the page to re-enter the information.
-
if ((count($results)-1)>0){
-
header('Location: index.php?
-
page=redirectOldClientsJobSheet.php&err=6'); }
-
-
//checks is the contact exists
-
elseif(mysql_num_rows(mysql_query("SELECT contactID FROM
-
CONTACTS WHERE first_name = '$firstName'
-
AND last_name = '$lastName' AND
-
email_address = '$email_address' "))){
-
-
mysql_query("INSERT INTO STATUS VALUES(
-
NULL,'$status','$description') ")
-
or die (mysql_error());
-
-
$statusID = mysql_query("SELECT statusID FROM STATUS WHERE
-
statusID = 'LAST_INSERT_ID()' ") or die (mysql_error());
-
-
mysql_query("INSERT INTO JOBSHEET VALUES(
-
NULL,'$clientID',LAST_INSERT_ID(),'$staffID','$COD','$billed',
-
CURRENT_DATE(),'$warranty','$jobID','$contactID','$title',
-
'$complete','$log')") or die (mysql_error());
-
-
header('Location: index.php?page=oldClientsEnteredInfoDisplay.php');
-
}
-
else{
-
header('Location: index.php?page=redirectOldClientsJobSheet.php&err=7');
-
}
-
}
-
?>