[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

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
0
bergertime
Asked:
bergertime
1 Solution
 
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
 
lenordisteCommented:
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
 
bergertimeAuthor Commented:
THanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now