473,394 Members | 1,766 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,394 software developers and data experts.

Clean up mySQL fields

Wm
I have three phone/fax number fields in a database that people are spamming
with text info (marketing hype B.S.) and I want to figure out how to clean
up the info and then limit it in the future. I think I need to do two
steps -- delete existing data in each field other than numbers and "-"
marks, and then limit the fields to ONLY numbers and "-" marks.

1. Is there a safe way to edit the existing data using phpMyAdmin? (I only
know how to to the preg_replace in PHP, but I know I can't do that in mySQL)

2. Other than the preg_replace, what's the best way to limit input in those
fields to only numbers and hyphens?

Thanx!
Wm


Jul 17 '05 #1
6 6536
On Tue, 30 Sep 2003 16:58:16 +0000, Wm wrote:
<snip!>
2. Other than the preg_replace, what's the best way to limit input in
those fields to only numbers and hyphens?


preg_* is a good way. what else do you need?

Another suggestion, though...

Set the column type to a number type -- int(10) or somesuch:

mysql> alter table information modify phone phone int(10);

Then strip all non-number characters out before you submit:

$phone = preg_replace("/\D/", "", $phone);

This will prevent any text data from being able to be submitted. Then
format the phone numbers later if you need to print them. It is always
easier to add formatting later than to have to change formatting once it
is in place.

WARNING: Untested code snippets! Use at own risk.
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #2
I noticed that Message-ID: <pa****************************@jhu.edu> from
Jeffrey Silverman contained the following:

Set the column type to a number type -- int(10) or somesuch:


and for a number like 01782555555 ?

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
On Tue, 30 Sep 2003 19:38:00 +0100, Geoff Berrow <bl@ckdog.co.uk.the.cat>
wrote:
I noticed that Message-ID: <pa****************************@jhu.edu> from
Jeffrey Silverman contained the following:
Set the column type to a number type -- int(10) or somesuch:


and for a number like 01782555555 ?


Exactly - phone numbers are not integers, they're strings. You can't add or
multiply two phone numbers together, and the leading zeroes are significant.

What about numbers like +4412341234134 as well? Use varchar.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #4
On Tue, 30 Sep 2003 20:48:20 +0100, Andy Hassall wrote:
<snip!>
Exactly - phone numbers are not integers, they're strings. You can't add
or
multiply two phone numbers together, and the leading zeroes are
significant.

What about numbers like +4412341234134 as well? Use varchar.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


Allrighty, I take it back. Don't use int(). But neither of you responded
with a solution for the OP. Any suggestions?

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #5
On Tue, 30 Sep 2003 16:58:16 GMT, "Wm" <LA*******@hotmail.com> wrote:
I have three phone/fax number fields in a database that people are spamming
with text info (marketing hype B.S.) and I want to figure out how to clean
up the info and then limit it in the future. I think I need to do two
steps -- delete existing data in each field other than numbers and "-"
marks, and then limit the fields to ONLY numbers and "-" marks.

1. Is there a safe way to edit the existing data using phpMyAdmin? (I only
know how to to the preg_replace in PHP, but I know I can't do that in mySQL)
There doesn't appear to be a 'filter' type function in MySQL, so a one-off
process of reading it in PHP, filtering through preg_replace, and doing an
update sounds like the way to go. Not really any neat way to do it with
phpMyAdmin I can think of.
2. Other than the preg_replace, what's the best way to limit input in those
fields to only numbers and hyphens?


The best way would be to use a database that support CHECK constraints, and
get the database to enforce it.

The next best way is at insert time with PHP; preg_match is a reasonable
choice there.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #6
I noticed that Message-ID: <pa****************************@jhu.edu> from
Jeffrey Silverman contained the following:
Allrighty, I take it back. Don't use int(). But neither of you responded
with a solution for the OP. Any suggestions?


He wants to clean up the data in the existing table right? AFAIK, you
can only edit a row at a time in phpMyadmin.

But if he knows how to do preg replace, presumably he can pull the data
from the table, preg replace it and then put it back?

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bruce A. Julseth | last post by:
Newbie Question: Is there a way to import MS Access into MySQL? Maybe create a CSV or something. If so, what would be the SQL to do this? Thanks... Bruce
4
by: Ben | last post by:
Hi I am new to C++ and I want to know if C++ is suitable for making a GUI application with a MySQL database. I also want to know what keywords in books I should look for. Is DATA STRUCTURES a...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
2
by: Sam White | last post by:
I have set up a MySQL db on one server, IIS 6.0 on another. Using Frontpage I created some forms to input data. On a test page I made, I have 4 fields. First is the ID which is autonumber (I leave...
2
by: pholck | last post by:
A newbie question here: I'm linking to a MySQL backend table with a million+ records, where two fields are of type datetime. However Access considers those fields to be text. Can't seem to get...
0
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer...
5
by: Marijn | last post by:
Hello everybody, I am new to PHP and working on extending my knowledge of OOP. The posts in this group concerned with whether or not to use an OO approach when programming in PHP is not what I...
0
by: John Kirkpatrick | last post by:
Hi all, I am having difficulty displaying records on a frontend MS Access 2000 form using a MySQL backend. The following code works well with the Jet database engine but doesn't work properly...
0
by: tedpottel | last post by:
Hi I am trying to right a script to keep a local copy of my mysql database in a local access file. I was able to do this in Access visual basic, but cannot get it to work in python. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.