Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

21 Experts available now in Live!

Get 1:1 Help Now