0

I want to select from my number table that haven't any character except + in index.
For example:

  • +991234567 is ok

  • 98+4587889 is not ok

  • 14asdasda54866666 is not ok

How should i write my query?

PhiLho
  • 40,535
  • 6
  • 96
  • 134
  • possible duplicate of [Detect if value is number in MySQL](http://stackoverflow.com/questions/5064977/detect-if-value-is-number-in-mysql) – Lloyd Nov 22 '12 at 09:49
  • What are you trying to do, what is your end outcome, are you simply checking for invalid numbers? – Lloyd Nov 22 '12 at 09:51
  • You can use Regular Expressions on MySQL to do so http://dev.mysql.com/doc/refman/5.1/en/regexp.html – Sir Rufo Nov 22 '12 at 09:52
  • @Lloyd i think he tries to check for valid phone numbers and internationals start with + ;o) but he should have mentioned it in question – Sir Rufo Nov 22 '12 at 09:54
  • @SirRufo yeah sry if my question not completly clear – user1718141 Nov 22 '12 at 09:57
  • So check out http://stackoverflow.com/questions/5064977/detect-if-value-is-number-in-mysql can probably just add a NOT somewhere. – Lloyd Nov 22 '12 at 09:59
  • but also your comments are misleading. @Lloyd asked if you are looking for invalid numbers. But +99.. is an invalid number. But it is not an invalid phone number. so you better be more precise – Sir Rufo Nov 22 '12 at 10:00

1 Answers1

0

Here is the Query with the Regular Expression

SELECT 
  number
FROM 
  Table1
WHERE 
  number NOT REGEXP '^\\+{0,1}(0|1|2|3|4|5|6|7|8|9)*$'

SQL Fiddle

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73