Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a string contains only numbers?

Tags:

vb.net

Dim number As String = "07747(a)"  If number.... Then  endif 

I want to be able to check inside the string to see if it only has number, if it does only contain numbers then run whatever is inside the if statment? What check do i use to check if the string only contains numeric and no alpha ot () etc ..?

What i am trying to check for is mobile numbers, so 077 234 211 should be accepted, but other alphas should not be

like image 822
Beginner Avatar asked May 26 '11 13:05

Beginner


People also ask

How do you check if a string only contains letters and numbers?

Use the test() method on the following regular expression to check if a string contains only letters and numbers - /^[A-Za-z0-9]*$/ . The test method will return true if the regular expression is matched in the string and false otherwise.

Can string contain only numbers?

On false , string has only numbers.

How do I check if a string contains only 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 only digits in Java?

Using Character.isDigit(char ch). If the character is a digit then return true, else return false.


1 Answers

You could use a regular expression like this

If Regex.IsMatch(number, "^[0-9 ]+$") Then  ...  End If 
like image 81
Bala R Avatar answered Oct 06 '22 13:10

Bala R