Solved

asp.net formview textbox numeric

Posted on 2013-06-27
3
344 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
[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
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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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