Hey,
I have two textbox called BIRTH
& EMAIL
, and I must test in button click if the user has typed a date & email format in those two TextBox.
How can do that ?
Hey,
I have two textbox called BIRTH
& EMAIL
, and I must test in button click if the user has typed a date & email format in those two TextBox.
How can do that ?
Take a look at DateTime.TryParse
for the date.
For the e-mail, unfortunately using regular expressions is probably your best bet.
Use a RegularExpressionValidator
for each field, in conjunction with a RequiredFieldValidator
. There are some ready made regular expressions for both that can be accessed through the properties window of the control.
The ValidationExpression
is where you set the regular expression.
Why dont you use the ASP .NET Validators?
http://support.microsoft.com/kb/316662
Seems like the RegularExpressionValidator along with the RequiredFieldValidator would be perfect for this.
Note: The Regular Expression Validator already has the email option in the pre populated list.
For the date field, I would use the date picker, or some other control that let the user enter the day, month, and year separately. That way you don't have to worry about ambiguous dates, such as 01/05/2010, or even worse 01/05/10 (is that y/m/d, d/m/y, m/d/y etc.), and other such problems. For email address, I would do a simple check for the "@" symbol, and a dot, but don't get any more stringent than that. Email addresses can be pretty weird. You can also make them type the email address twice to ensure that they typed it correctly.
As you're using VB.NET, I believe IsDate(dateValue) is a simple option to validate the date.
Regular Expressions are your best bet though.
There's a fairly long discussion on SO regarding email regexes here: