Solved

Test the format of a string

Posted on 2008-09-30
2
173 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

20 Experts available now in Live!

Get 1:1 Help Now