Jump to content

mysql regular expression


lenerd3000

Recommended Posts

hello,

 

anyone here knows this problem?

 

i have phone numbers in my database and there's 3 formats

1. (555) 235-6589

2. 125 246 4256

3. 124.265.1545

 

my problem is how can i compare my input from my phone number. i need a unique phone number in my database. what if the inputted format is 265 568 5659 how can i compare it in a phone number with this format 265.568.5659 or (265) 568-5659. i know how to get numbers in the inputted data but i dont know how to get numbers from the database's phone numbers so that the comparing of the two data will be all number like this 2655865659 = 2655865659.... any good idea for this problem? i appreciate it most.

Link to comment
Share on other sites

It's never too late to clean things up :) You're essentially going to be doing the same process, the only difference is whether the database itself is modified or not.

 

Perhaps something like:

 

SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(phone, '(', ''), ')', ''), '-', ''), '.', ''), ' ', '') AS phone;

Link to comment
Share on other sites

this is my expression:

 

select '858-659-5595' REGEXP '?[\(]858?[\)]?[\-\. ]659?[\-\. ]5595'

 

but it produce this error:

 

#1139 - Got error 'repetition-operator operand invalid' from regexp

 

my only problem is how can i tell the regexp the parenthesis () is optional. the rest is ok only the parenthesis part is not.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.