Solved

Test the format of a string

Posted on 2008-09-30
2
172 Views
Last Modified: 2010-04-23
Folks:

In VB.NET, I need to test a string for the following: whether it has any non-numeric characters, or a leading zero.

Good:
1234567
1234
8888853

Bad:
012345
12/3345
234,445
10-23-34-89

TIA!
0
Comment
Question by:crafuse
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 250 total points
ID: 22605176
Hi crafuse,

Try this function....

    Public Function TestNumeric(ByVal num As String) As Boolean
        If num.Substring(0, 1) = "0" Then
            Return False
        Else
            Dim n As Integer = Nothing
            Integer.TryParse(num, n)
            Return n <> Nothing
        End If
    End Function

Regards,

Wayne
0
 

Author Closing Comment

by:crafuse
ID: 31501535
Sweet.

Thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now