473,325 Members | 2,771 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,325 software developers and data experts.

date, phone and zip edits

114 100+
Hi to all. PHP newbe here.

Would like to know what is the simplest way to edit/validate dates, phone numbers and zip codes that are entered on a form. This data will be saved in a MySQL database if these fields contain valid formated data that is within allowable ranges.

Are there examples that I could get of these editing functions or how to code for this type of edits.

Thanks for any help in advance.
Jan 4 '07 #1
7 1513
ronverdonk
4,258 Expert 4TB
Simplest is to use regular expressions. HOWEVER, you have to know what format you want to use. I.e. a US telephone no is quite different from a UK or a German telephone no. Same applies to ZIP or postal codes and date formats (US, ISO, etc.). So first decide on the required format, then we can discuss the regular expressions that should be used.

Ronald :cool:
Jan 4 '07 #2
ljungers
114 100+
Thanks for a reply. As to formats they all will be in US format. Dates will eiter be in mmddyy or mmddyyyy format. Phone number I know that input wise I have seen 3 formats allowed like (123) 123-1234, 123-123-1234, 1231231234. Zip will be zip +4 allowed if they have the +4.

Can multi formats be allowed plus edited or is it best to stick to one format allowed. Have been told that I should remove the - / ( ) from these fields prior to storing them in MySql. Is that true or just one way of storing data.
Jan 4 '07 #3
ronverdonk
4,258 Expert 4TB
A bit of searching on the web resulted in these:
[php]Matching US phone numbers in the following formats:

###-###-####
(###) ###-####
##########

Restricts area codes to >= 200 and exchanges to >= 100, since values below these are invalid.
$pattern = "/(\([2-9]\d{2}\)\s?|[2-9]\d{2}-|[2-9]\d{2})"
. "[1-9]\d{2}"
. "-?\d{4}/";[/php]
[php]US zip pattern 5 digits (01234) or 5 digits + 4 (01234-1234)

$pattern = '^[0-9]{5}([- /]?[0-9]{4})?$^';[/php]

Ronald :cool:
Jan 5 '07 #4
ljungers
114 100+
Thanks for the info & code. Would the date edits be simiular and I forgot to ask about decimal/number and currency edit's. The decimal or number fileds would be for number of months or number of persons. The currency would be for dollar amounts 9,999,999.99, 9,999,999.99-, or 9999999.99, 9999999.99-

Thank you and will check back tomorrow
Jan 5 '07 #5
ronverdonk
4,258 Expert 4TB
Forgot the US dates
Expand|Select|Wrap|Line Numbers
  1. // US date formats MMDDYY and MMDDYYYY
  2. $pattern = '^(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])(19|20)?\d\d^';
and the US currency[php]$tests = array(" $ 42.52 ",
"$ 4232395",
"4112412",
"239583.52",
"$ 3223.23",
"$123,234.53",
"$123,235",
"$ 123,234,325.23");
$pattern = '/^\s*[$]?\s*((\d+)|(\d{1,3}(\,\d{3})+))(\.\d{2})?\s*$/';
foreach ($tests as $test) {
// US currency
if (preg_match($pattern, $test)) {
echo "Matched on $test<br />";
}
else {
echo "Failed match on $test<br />";
}
}
?>[/php]
Ronald :cool:
Jan 5 '07 #6
ljungers
114 100+
Thank you for your help.
Jan 5 '07 #7
ronverdonk
4,258 Expert 4TB
You are welcome any time.

Ronald :cool:
Jan 5 '07 #8

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

Similar topics

10
by: Fawke101 | last post by:
Hi there, I have a date field in SQL server - that holds dates as DD/MM/YYYY format (GB). Now, i have an ASP application that Adds/Edits records in this table; and i am having real problems...
6
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is...
1
by: Miranda Evans | last post by:
In my application, a text box control resides in a form. The text box control is unbound, but--assuming all edits are passed when the user click a command button on the form--the contents of the...
3
by: Evelyn Pabón | last post by:
Hi I'm developing a database with access and I was ask to include in the report the date of issue. But if the date of issue was change It should be included in the footnote area the issue date...
1
by: ET | last post by:
Please help with the query: There are two tables, A and B. A table has information about cell phones, like cell number, sim number, model, manufacturer etc... B table has user related...
9
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database...
11
by: Mike9900 | last post by:
How can I get the real system date/time if the user fakes the date, for example by setting the system date back. -- Mike
0
by: oneplace | last post by:
I have the following script that use for the following after i have made my search for a name in my database. I select the name and it bring up this from with all the information of the person. It...
9
by: ice | last post by:
Hello, I have a couple of tables. The client tables and the contacted tables. I am not sure how to start on this, what I need is a way to query all my clients then show any client that the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.