Email validation control or code for VB.Net 2005.
-
16 aprilie 2007 09:56I am developing a windows application using VB.Net 2005.
One of my forms contains a textbox for entering email id. I want to validate its patterns i.e. It should have @, atleast one ".", etc.
In asp.net we have validation control for this.
But how to do it in VB.Net 2005.
Toate mesajele
-
16 aprilie 2007 10:03
Hi,
using Regular expressions you can do that.
see
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=817098&SiteID=1
Thanks,
Ch.T.Gopi Kumar.
- Propus ca răspuns de Enes Karagedik 4 octombrie 2012 19:53
- Anulare propunere ca răspuns de Enes Karagedik 4 octombrie 2012 19:53
-
16 aprilie 2007 10:45Could you please tell me the namespace which I have to import for using regex.
-
16 aprilie 2007 11:45
Harsh wrote: Could you please tell me the namespace which I have to import for using regex. It's System.Text.RegularExpressions
see http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx
Thanks,
Ch.T.Gopi Kumar.
-
16 aprilie 2007 12:33
Hi I tried to use following code -
Imports
System.Text.RegularExpressionsIn one of my functions-
If
txtEmail_1.Text <> "" Then Dim rex As Match = Regex.Match(Trim(txtEmail_1.Text), "[a-z0-9._]*@[a-z0-9_]*(\.[a-z0-9_]{2,4}){4}", RegexOptions.IgnoreCase) If rex.Success = False ThenMessageBox.Show(
"Please Enter a valid Email-Address 1", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)txtEmail_1.Focus()
Exit Function End If End IfBut it is always giving rex.success as false.
I entered correct email also still it is false.
Please tell me whether the compare condition is correct or not
-
16 aprilie 2007 13:05
Hi,
I've found one more good link,consisting the predefined regular expressions for currency,e-mail,zip code etc at
http://msdn2.microsoft.com/en-us/library/ms998267.aspx
So ,using the e-mail validation expression given in the above page,
your code would become as follows
If txtEmail_1.Text <> "" Then Dim rex As Match = Regex.Match(Trim(txtEmail_1.Text), "^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3})$", RegexOptions.IgnoreCase)
If rex.Success = False Then MessageBox.Show("Please Enter a valid Email-Address 1", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtEmail_1.Focus() Exit Function End If End If
This works fine.
Thanks,
Ch.T.Gopi Kumar.
-
17 aprilie 2007 07:40Thanks
-
5 noiembrie 2007 10:51
imports.system.text.regularexpressions
]
frm:lucky(btech)
-
5 noiembrie 2007 10:51
-
5 noiembrie 2007 11:10
what is web page desgine?
-
5 noiembrie 2007 11:35
th u -
5 noiembrie 2007 11:39
means of listbox -
5 noiembrie 2007 11:41
listbox created -
22 mai 2008 03:08
hi i got ur email thanks for help but wat is a data type of "MATCH" reply me soon
-
22 mai 2008 03:09
ok i got it sorry -
28 mai 2008 00:11
thanks for ur help it is very use full to me but can u give me the string which provide ( . ) Dot also in the fisrt name of email address for user
i am waiting for your reply
-
28 mai 2008 00:13
u sended me this string like
Dim rex As Match = Regex.Match(Trim(pobjSender.ValueText), "^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3})$", RegexOptions.IgnoreCase)"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3})$"
-
28 august 2008 10:31
Can u plz explain this code.
Meas for what purpose * is used before @
What is the meaning of (,),{,} bracks....
Thank u.. -
25 septembrie 2008 05:16
Sorry for late reply i hope still this help you .
this will give all string manipulation
http://www.devarticles.com/c/a/VB.Net/Regular-Expressions-in-.NET/1/
-
14 aprilie 2010 03:03You can also try this Ultimate Email Validator component.
-
17 iulie 2011 03:44
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub btnEmailCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmailCheck.Click
Dim st As String
st = "^([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 reg As New Regex(st)
If reg.IsMatch(txtEmail.Text) Then
MessageBox.Show("Email Valid")
Else
MessageBox.Show("Email Not Valid")
End If
End Sub
End Class
SChahal -
12 februarie 2012 19:36good help, thanks