Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to strip a string of all alpha's?

Tags:

vb.net

Dim phoneNumber As String = "077 47578 587(num)"

How do i strip the above string off every character which isnt a number. So only the numbers are left and then check to make sure it is 11 characters long?

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

Beginner


People also ask

How do you remove all alphanumeric characters from a string in Python?

Here in our tutorial, let us do this using isalnum(). We can also do this using regular expressions and isalpha(), isnumeric(). Most importantly, we use isalnum() because it is the easiest way to delete alphanumeric elements from the list.

How do I remove a character from a number string?

The idea is to use String. replaceAll() method that replaces all the sequence of characters that matches the given Regular Expression with the given replacement string.

How do I remove non alphanumeric characters from a string in CPP?

Remove all non alphanumeric characters from a string in C++The std::remove_if algorithm returns an iterator that indicates where the end should be, which can be passed to the std::erase function. Starting with C++20, consider using the std::erase_if function that is error-free wrapper over the erase-remove idiom.

How do you filter alphanumeric in Python?

Using isalnum() function Another option is to filter the string that matches with the isalnum() function. It returns true if all characters in the string are alphanumeric, false otherwise.


1 Answers

dim number as string = Regex.Replace(phoneNumber,"[^0-9]","")

if number.length = 11 then
 'valid number
else
 'not valid
end if
like image 128
Matt Avatar answered Sep 18 '22 22:09

Matt