How to check a text box for a valid email address
-
Hello, I attach a textbox on the form. How can i check a text box for a valid email address. Means if user enters invalid address in a text box e.g (aaaa.com), then it will alert a message. plz reply. EsHbAn BaHaDuR
u can force user to enter valid email u can force him to enter username(just username) in one textbox and domain(e.g. rediff, yahoo) in another username (textbox here) @ domain(textbox here) then u can cancatenate string as dim str as string=textbox1.text+"@"+textbox2.text i think this logic will work all the best
-
u can force user to enter valid email u can force him to enter username(just username) in one textbox and domain(e.g. rediff, yahoo) in another username (textbox here) @ domain(textbox here) then u can cancatenate string as dim str as string=textbox1.text+"@"+textbox2.text i think this logic will work all the best
That's a horrible solution considering it allows for all kinds of invalid characters in the address... A better solution is to use a Regular Expression to do the validation. There are many examples of this all over the web. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Hello, I attach a textbox on the form. How can i check a text box for a valid email address. Means if user enters invalid address in a text box e.g (aaaa.com), then it will alert a message. plz reply. EsHbAn BaHaDuR
Use a Regular Expression (RegEx class) to evaluate if the address is sytactically correct:
Public Function IsEmail(ByVal emailAddress As String) As Boolean
Dim strRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & _
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" & _
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
Dim re As New Regex(strRegex)
If re.IsMatch(emailAddress)
Return True;
Else
Return False
End Function* Code snippet taken from this[^] Code Project article by Vasudevan Deepak Kumar. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome