Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to validate textbox in asp.net

Posted on 2008-10-21
3
Medium Priority
?
2,813 Views
Last Modified: 2012-05-05
how can i validate a  textbox to accept only date values or textbox to accept only integer values in asp.net
0
Comment
Question by:neil17317
[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 6

Accepted Solution

by:
M3mph15 earned 1500 total points
ID: 22773301
Hi,
For both date and integers you can use a Regular ExpressionValidator.
To Validate a date it would be soemthing like this:
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"  ControlToValidate="txtDate" ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$">Date needs to be in the format dd/MM/yyyy</asp:RegularExpressionValidator>
And for intergers it would be
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"  ControlToValidate="txtDate" ValidationExpression="\d{4}">Date needs to be in the format dd/MM/yyyy</asp:RegularExpressionValidator>
the 4 in \d{4} is the length of the integers
Hope this helps
-M3mph15
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22779276
A little note on the integer validation.
\d{4} will take 0000 as a valid integer.
Use this to validate 4-digit integer:
^[1-9]\d{3}$
For any length, use
^[0-9]|{1-9]\d*$
0
 

Author Comment

by:neil17317
ID: 22864018
sorry i have'nt mentioned about the time..i'm currently validating about textbox which should only accept datetime format .. do you have a could for this... thanks.................please help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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