views:

36

answers:

5

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 ?

A: 

Take a look at DateTime.TryParse for the date.

For the e-mail, unfortunately using regular expressions is probably your best bet.

Chris Pebble
and for the email ?
dotNET
A: 

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.

Oded
A: 

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.

Barry
A: 

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.

Kibbee
A: 

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:

http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses

Damien Dennehy