Email Validation

  • Thread starter Thread starter Kiran B.
  • Start date Start date
K

Kiran B.

Hi, how can I validate the fomat for valid email and the most important is
if that email is real working email...sort of checking mx record? How can i
do this in asp.net

Thanks in advance....

KB
 
Kiran B. said:
Hi, how can I validate the fomat for valid email and the most important is
if that email is real working email...sort of checking mx record? How can i
do this in asp.net

Thanks in advance....

KB
I use the following. I am sure there are other ways but it works for me.
<asp:RegularExpressionValidator id="RequiredEmail1" runat="server"
ControlToValidate="Email1"
InitialValue=""

ValidationExpression="^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|
(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
Display="Static"
Font-Name="verdana" Font-Size="10pt">
* valid e-mail address required
</asp:RegularExpressionValidator>
<asp:CustomValidator id="CustomValidator1" runat="server"
ControlToValidate="Email1"
OnServerValidate="ServerValidate"
Display="Static"
Font-Name="verdana" Font-Size="10pt">
* valid mail server name required.
</asp:CustomValidator>

My code for validating the server name is

Sub ServerValidate (sender As Object, dnsvalue As ServerValidateEventArgs)
dim strDomain as string
dnsvalue.IsValid = False
Try
dim int as int32
int = instr(2,dnsvalue.Value,"@")
strDomain = mid(dnsvalue.value,int+1,999)
If not Dns.GetHostByName(strDomain).hostname is null Then
dnsvalue.IsValid = True
End If
Catch
End Try
RequiredEmail1.text = ""
End Sub
 
Back
Top