Solved

Test the format of a string

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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