• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

Need to restrict input to positive integer numbers between 1 and 100 inclusive

I have an asp.net text box. I need restrict the application user to entering only positive integer values greater than Zero and less than or equal to 100. What is the best way to do this not using Java Script? But using Asp.net? If a regular expression is the best way, I am open to that, but I will need some help.
  • 2
2 Solutions
Paul JacksonSoftware EngineerCommented:
Use an ASP.net rangevalidation control
Paul JacksonSoftware EngineerCommented:
Honestly, Javascript would be best since it can be done on the client side but if you must use ASP.net, in the OnClick event of your submit button you can validate it by using the following:

Dim intValue As Integer

' Verify Integer
intInteger = CInt(textboxname.text.trim)
' Verify Between Values
If intInteger <0 OR intInteger > 100 Then
lblError.text = "Invalid Value. Must Be Between 1 and 100."
Exit Sub

' Other Processing Rules...
End If
Catch ex As Exception
lblError.text = "Invalid Integer
Exit Sub
End Try

Open in new window

lblError is just a label on your form to display the error message to the user.
brgdotnetcontractorAuthor Commented:
Thank you!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now