Querystring validation

Posted on 2012-09-17
Last Modified: 2012-09-17
Validating Request.Querystring in VB code behind.

I have two...

Because of bad design which I'm correcting I have to validate both.

CategoryID is supposed to be an integer...the other is a string
What's best way to verify CategoryID is an integer?
Question by:lrbrister
    LVL 23

    Accepted Solution

    You can use a function to check it (see below).

    check if its blank and check if its numeric with the function below

    Public Function IsNumeric(ByVal str As String)
     Dim r As Regex = New Regex(“\d+”)
    Dim m As Match = r.Match(str)
     If (m.Success) Then
     Return True
     End If
     Return False
     End Function
     If Not (IsNumeric(TextBox4.Text)) Then
     MessageBox.Show(“A listening port must be a numeric value”, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error)
     End If

    Open in new window

    LVL 23

    Assisted Solution

    note : I grabbed the function for here hence the error message about a port number :)
    LVL 23

    Assisted Solution

    So you can use IsNumeric which appears to be built into Vb.Net (I use c# so apologies for the long list of posts)

    Here is another good resource incase your interested in other validation:

    Author Closing Comment


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now