Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a string contains numbers

How do I check if a string in a MySQL field contains a number then delete them?

Example table:

tbl_tags  ------------- | id | tag    |  ------------- | 1  | hello  | | 2  | hello2 | | 3  | 2hello | | 4  | hel3lo |  ------------- 

The only way I can think of is to do each number individually and use LIKE '%1%' OR LIKE '%2%' etc. But there must be an easier way?

like image 598
pjau Avatar asked Jul 17 '10 01:07

pjau


People also ask

How do you check if a character in string is a number?

We can check whether the given character in a string is a number/letter by using isDigit() method of Character class. The isDigit() method is a static method and determines if the specified character is a digit.

How do you check if a string contains any numbers in Python?

Python String isnumeric() Method The isnumeric() method returns True if all the characters are numeric (0-9), otherwise False. Exponents, like ² and ¾ are also considered to be numeric values. "-1" and "1.5" are NOT considered numeric values, because all the characters in the string must be numeric, and the - and the .

How do you check if a string contains all numbers in Java?

To check if String contains only digits in Java, call matches() method on the string object and pass the regular expression "[0-9]+" that matches only if the characters in the given string are digits. String.

Can string contain numbers?

A string consists of one or more characters, which can include letters, numbers, and other types of characters. You can think of a string as plain text. A string represents alphanumeric data.


1 Answers

Check out the MySQL Regex methods. Something like the following should work.

SELECT * FROM table WHERE tag REGEXP '[0-9]' 
like image 180
Jason McCreary Avatar answered Sep 17 '22 14:09

Jason McCreary