asp.net formview textbox numeric

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
LVL 2
bergertimeAsked:
Who is Participating?
 
lenordisteConnect With a Mentor Commented:
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
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
you could use javascript regular expressions.

the following link would help with them.

http://www.regular-expressions.info/javascriptexample.html
0
 
bergertimeAuthor Commented:
THanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.