Solved

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

Posted on 2011-02-23
4
858 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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