"C.R.Vegelin" <[EMAIL PROTECTED]> wrote: > > Hi everybody, > I looked for a function to test whether a string is numeric (having > characters 0..9 only). I found in the 5.0 manual Cast() and Convert(), but > I don't think these do what I need. Any suggestion what function to use ? > Thanks in advance, Cor
Gleb Paharenko wrote:
Hello. Possible solution is to use REGEXP: mysql> select '911' regexp '^[1-9]*$'; +-------------------------+ | '911' regexp '^[1-9]*$' | +-------------------------+ | 1 | +-------------------------+ mysql> select '91a1' regexp '^[1-9]*$'; +--------------------------+ | '91a1' regexp '^[1-9]*$' | +--------------------------+ | 0 | +--------------------------+
This is close, but not quite what you want, I think. The problem is that this will also match empty strings:
mysql> SELECT '' REGEXP '^[1-9]*$'; +----------------------+ | '' REGEXP '^[1-9]*$' | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec) That's easily fixed, though. Just change the * to a +. mysql> SELECT '' REGEXP '^[1-9]+$'; +----------------------+ | '' REGEXP '^[1-9]+$' | +----------------------+ | 0 | +----------------------+ 1 row in set (0.00 sec) Michael -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]