473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

IsNumeric()

16
So I'm passing a masked telephone number in the form of (999)999-9999 to a Function that 'strips' the numbers out and puts them into a string that I then use in an Update SQL statement. So far I have the code below that of course doesn't do anything:

Function StripPhone(ByVal sPhone as String) as String
Dim i as Integer
Dim sStripped as String

For i = 1 to Len(sPhone)
If IsNumeric(Mid(sPhone, i)) Then
sStripped = i
sStripped = sStripped & Mid(sPhone, i)
End if
i = i + 1
Next
StripPhone = sStripped
End Function
Mar 10 '09 #1
6 2309
MrMancunian
569 Expert 512MB
So what's your question here?

Steven
Mar 10 '09 #2
mwcapps
16
My question is: How do I test the data to see if the characters are numbers? And how do I add them to a string if they are?
Mar 11 '09 #3
MrMancunian
569 Expert 512MB
You were pretty close. This is the correct code:

Expand|Select|Wrap|Line Numbers
  1. Function StripPhone(ByVal sPhone As String) As String
  2.   Dim i As Integer
  3.   Dim sStripped As String = ""
  4.   For i = 1 To Len(sPhone)
  5.     If IsNumeric(Mid(sPhone, i, 1)) Then
  6.       sStripped = sStripped & Mid(sPhone, i, 1)
  7.     End If
  8.   Next
  9.   Return sStripped
  10. End Function
  11.  
The For-Next-loop already increases i, so you didn't have to do that. sStripped = i doesn't make sense, as you don't want it to be the counter, but a part of the string. Further, Mid is used as Mid(string, start, length). This way, it is crystal clear which part of the string you want to check.

Steven
Mar 11 '09 #4
mwcapps
16
Mr. Steve,

Thank you sooo much. That worked, which I'm sure you're not surprised. You solved in an hour what I've been working on for 3 weeks. Thanks again for your help.
Mar 11 '09 #5
aryanbs
42
@mwcapps
I am surprised how do you know it took him an hour?
Mar 11 '09 #6
aryanbs
42
And One more thing, If its a MaskedTextBox then there is a property called
TextMaskFormat, setting it to ExcludePromptAndLiterals gives the text only from its text property.
Mar 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
4
by: Eugene Anthony | last post by:
I have received the following feedback for the two functions bellow: "The ISNUMERIC test is WORTHLESS for checking for an INT value, because ISNUMERIC will happily accept DOUBLE values, such as...
14
by: Kenny | last post by:
Hello, I would like to know if the function IsNumeric requires a header like #include <iostream> to be functionnal thanks ken
8
by: John Bowman | last post by:
Hello, Does anyone have a good/reliable approach to implementing an IsNumeric() method that accepts a string that may represent a numerical value (eg. such as some text retrieved from an XML...
3
by: martin | last post by:
Hi, is there a dotnet function (other than the old isnumeric from VB) to check whether an object is numeric or not. also I notice that all the old vb functions such as split / isnumeric /...
7
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a...
8
by: moondaddy | last post by:
What's the .net framework equivalent of the vb function isnumeric? If there isn't one, how can I test a string variable to see if its a number or not? I don't want to use isnumeric if possible ...
12
by: sck10 | last post by:
Hello, I am trying to determine if a value is NOT numeric in C#. How do you test for "Not IsNumeric"? protected void fvFunding_ItemInserting_Validate(object sender, FormViewInsertEventArgs...
12
by: Paul | last post by:
Hi, I am trying to check a string to see if it's first 3 characters are numeric and if they are, to replace those 3 characters with something else. I've tried this but nothing happens... ...
17
by: MLH | last post by:
I have tested the following in immed window: ?isnumeric(1) True ?isnumeric(1.) True ?isnumeric(1.2) True ?isnumeric(1.2.2)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.