Solved

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

Posted on 2011-02-23
4
866 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:brgdotnet
[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
4 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34966995
Use an ASP.net rangevalidation control
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 150 total points
ID: 34967003
0
 

Assisted Solution

by:sshull
sshull earned 150 total points
ID: 34967004
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

Try 
' 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.
0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 34969967
Thank you!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 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