?
Solved

Test the format of a string

Posted on 2008-09-30
2
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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