Querystring validation

Validating Request.Querystring in VB code behind.

I have two...
CategoryID
CategoryName

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?
lrbristerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aprestoConnect With a Mentor Commented:
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

0
 
aprestoConnect With a Mentor Commented:
note : I grabbed the function for here hence the error message about a port number :)

http://www.janinedalton.com/blog/archives/2004/looking-for-isnumeric-in-vbnet/
0
 
aprestoConnect With a Mentor Commented:
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:

http://visualbasic.w3computing.com/vb2008/2/vb-isnumeric-isdate-isarray.php
0
 
lrbristerAuthor Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.