Solved

Test the format of a string

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

Technology Partners: 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

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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