Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp.net formview textbox numeric

Posted on 2013-06-27
3
Medium Priority
?
353 Views
Last Modified: 2013-07-02
Using visual studio 2010 .NET 4.0.  I want to restrict a textbox to numeric only.  The control is in a formview.  Using vb.

Thanks
0
Comment
Question by:bergertime
3 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 39282769
you could use javascript regular expressions.

the following link would help with them.

http://www.regular-expressions.info/javascriptexample.html
0
 
LVL 11

Accepted Solution

by:
lenordiste earned 2000 total points
ID: 39283959
i would personally use a built in validator control such as the RegularExpresssionValidator. Example if your textbox has ID "TextBox1":

<asp:RegularExpressionValidator id="regVal1"
                   ControlToValidate="TextBox1"
                   ValidationExpression="\d+"
                   Display="Static"
                   EnableClientScript="true"
                   ErrorMessage="Please enter a numeric value."
                   runat="server"/>

Open in new window


you may also want to look at the range validator if you want to restrict the input further:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.rangevalidator.aspx
0
 
LVL 2

Author Closing Comment

by:bergertime
ID: 39293184
THanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 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