Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a string contains at least a number?

How to detect if a string contains at least a number (digit) in SQL server 2005?

like image 609
Manish Avatar asked Apr 01 '10 07:04

Manish


People also ask

How do you check if a string has at least one number?

To check if a string contains at least one number using regex, you can use the \d regular expression character class in JavaScript. The \d character class is the simplest way to match numbers.

How do you check if a string includes a number?

To find whether a given string contains a number, convert it to a character array and find whether each character in the array is a digit using the isDigit() method of the Character class.

How do you check if a string contains at least one number in Python?

To check if a string contains a number in Python:Use the str. isdigit() method to check if each char is a digit. Pass the result to the any() function. The any function will return True if the string contains a number.

How do you check whether a string contains a number or not in JavaScript?

To check if a string contains numbers in JavaScript, call the test() method on this regex: /\d/ . test() will return true if the string contains numbers. Otherwise, it will return false .


2 Answers

Use this:

SELECT * FROM Table WHERE Column LIKE '%[0-9]%' 

MSDN - LIKE (Transact-SQL)

like image 172
cjk Avatar answered Oct 04 '22 20:10

cjk


DECLARE @str AS VARCHAR(50) SET @str = 'PONIES!!...pon1es!!...p0n1es!!'  IF PATINDEX('%[0-9]%', @str) > 0    PRINT 'YES, The string has numbers' ELSE    PRINT 'NO, The string does not have numbers'  
like image 40
kevchadders Avatar answered Oct 04 '22 21:10

kevchadders