TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sticky Mail
NA
1
1.3k
C# - Try parse not working
Jan 1 2015 10:11 PM
while validating date of birth,if the month contains string or character,int32.tryparse returns false,which should be true and the code moves to else part.
I want the user to use DD MM YYYY format and numeric like 12 02 2014.For testing.I entered a string in the month field but it is not throwing error.My input was 12 sx 2014.
Can someone shed some light on this.
if (dobMonth.Text == String.Empty || !Int32.TryParse(dobMonth.Text, out intParsed))
{
valid = false;
dobMonth.CssClass = "error";
ErrDOB.Visible = true;
}
else
{
}
<div><label>Date of Birth:<span class="req-field">*</span></label></div>
<div><span><asp:TextBox ID="txtDOBDay" Text="DD" MaxLength="2" runat="server" /></span></div>
<div><span><asp:TextBox ID="txtDOBMonth" Text="MM" MaxLength="2" runat="server" /></span></div>
<div><span><asp:TextBox ID="txtDOBYear" Text="YYYY" MaxLength="4" runat="server" /></span></div>
Reply
Answers (
1
)
.net
How to validate a textbox control Asp.Net