0

I have the following RegExp in mySQL:

WHERE telephone NOT REGEXP'(^[+][0-9]+\ )?([0-9]{3}\-[0-9]{3}\-[0-9]{4})(\ x[0-9]+$)?'

This is supposed to select all phone numbers that are not in the +0 000-000-0000 x000 format. It works almost perfectly except I have one customer that entered in 000-000-0000</span> into the telephone field and this expression does not find it. I know I have it set to accept an optional extension, but how do I make sure that optional extension is in the correct format?

3
  • What if you change (\ x[0-9]+$)? to (\ x[0-9]+)?$ ? You may also want to change (^[+][0-9]+\ )? to ^([+][0-9]+\ )? Commented May 2, 2015 at 17:15
  • Cleanse your data of </span> (etc) before storing into a table. Commented May 4, 2015 at 0:10
  • @rick LOL that's the whole reason I wrote the function. I to clean out all the crap people have put in and not allow anything like it in the future. Commented May 4, 2015 at 2:07

1 Answer 1

1

Add an ending anchor to what you have:

^([+][0-9]+\ )?([0-9]{3}\-[0-9]{3}\-[0-9]{4})(\ x[0-9]+)?$

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.