473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

php regular expressions

Hie

could someone please help me> I'm trying to use a regular expression to validate and address and it is as follows.

eregi('(^[a-zA-Z0-9 \\\.,-]+)$',$value4)

$value4 = 10/54 kent street;

I want to allow the users to put in slashes as part of their addresses so I'm looking 4 a simple regular expression to do that.

Thank you
May 13 '07 #1
3 1424
Atli
5,058 Expert 4TB
Hie

could someone please help me> I'm trying to use a regular expression to validate and address and it is as follows.

eregi('(^[a-zA-Z0-9 \\\.,-]+)$',$value4)

$value4 = 10/54 kent street;

I want to allow the users to put in slashes as part of their addresses so I'm looking 4 a simple regular expression to do that.

Thank you
If I'm not very much mistaken, putting a '/' in front of your '\\\' would do the trick.
May 13 '07 #2
pbmods
5,821 Expert 4TB
You'll probably want something like this:

Expand|Select|Wrap|Line Numbers
  1. preg_match('/^[\d]+(\/[\d]+)?(\b\w)+$/', $value4);
  2.  
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):

Expand|Select|Wrap|Line Numbers
  1. preg_match('/^[\d]+(\/[\d]+)?(\b\d*\w)+$/', $value4);
  2.  
For more info:
http://www.regular-expressions.info/reference.html
May 15 '07 #3
You'll probably want something like this:

Expand|Select|Wrap|Line Numbers
  1. preg_match('/^[\d]+(\/[\d]+)?(\b\w)+$/', $value4);
  2.  
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):

Expand|Select|Wrap|Line Numbers
  1. preg_match('/^[\d]+(\/[\d]+)?(\b\d*\w)+$/', $value4);
  2.  
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:

Expand|Select|Wrap|Line Numbers
  1. function isWord($value,$pageURL){
  2. $value2 = trim(stripslashes($value));
  3. f((strlen($value2) == 0) or (!ereg("^[[:alpha:]'-]{1,100}$",$value2))){
  4. $uri = "//" . $_SERVER["SERVER_NAME"]. rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
  5. header("Location: http:".$uri.$pageURL."&err=1");
  6. }else{
  7. return $value2;
  8. }
  9. }
[Please use CODE tags when posting source code. Thanks! --pbmods]

I then called it in dbJobsheet as follows:

Expand|Select|Wrap|Line Numbers
  1. $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:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $timeQuery = mysql_query("SELECT date_assinged,time_assigned,assStaffID 
  3.  
  4. FROM FOLLOW_UP WHERE
  5. time_assigned ='$newTime' AND 
  6. date_assinged = '$newAssignedDate' 
  7. AND assStaffID = '$assStaffID' ")
  8. or die(mysql_error());
  9.  
  10. $results = mysql_fetch_array($timeQuery);
  11. //checks if there is a time clash and redirects user to the page to re-enter the information. 
  12. if ((count($results)-1)>0){ 
  13. header('Location: index.php? 
  14. page=redirectOldClientsJobSheet.php&err=6'); } 
  15.  
  16. //checks is the contact exists
  17. elseif(mysql_num_rows(mysql_query("SELECT contactID FROM 
  18. CONTACTS WHERE first_name = '$firstName' 
  19. AND last_name = '$lastName' AND 
  20. email_address = '$email_address' "))){
  21.  
  22. mysql_query("INSERT INTO STATUS VALUES(
  23. NULL,'$status','$description') ") 
  24. or die (mysql_error());
  25.  
  26. $statusID = mysql_query("SELECT statusID FROM STATUS WHERE
  27. statusID = 'LAST_INSERT_ID()' ") or die (mysql_error());
  28.  
  29. mysql_query("INSERT INTO JOBSHEET VALUES(
  30. NULL,'$clientID',LAST_INSERT_ID(),'$staffID','$COD','$billed',
  31. CURRENT_DATE(),'$warranty','$jobID','$contactID','$title',
  32. '$complete','$log')") or die (mysql_error()); 
  33.  
  34. header('Location: index.php?page=oldClientsEnteredInfoDisplay.php'); 
  35. }
  36. else{ 
  37. header('Location: index.php?page=redirectOldClientsJobSheet.php&err=7');
  38. }
  39. ?>
May 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Michael McGarry | last post by:
Hi, I am horrible with Regular Expressions, can anyone recommend a book on it? Also I am trying to parse the following string to extract the number after load average. ".... load average:...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
13
by: Wiseman | last post by:
I'm kind of disappointed with the re regular expressions module. In particular, the lack of support for recursion ( (?R) or (?n) ) is a major drawback to me. There are so many great things that can...
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.