Sticky Mail

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>

Answers (1)