Harsh585762

I 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.


Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

TilakGopi

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.






Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

Harsh

Could you please tell me the namespace which I have to import for using regex.



Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

TilakGopi

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.






Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

Harsh

Hi I tried to use following code -

Imports System.Text.RegularExpressions

In 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 Then

MessageBox.Show("Please Enter a valid Email-Address 1", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

txtEmail_1.Focus()

Exit Function

End If

End If

But 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





Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

TilakGopi

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.






Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

Harsh

Thanks



Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

lucky123321

imports.system.text.regularexpressions

]

frm:lucky(btech)






Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

lucky123321






Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

just jenny

what is web page desgine






Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

raj_login

th u




Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

raj_login

means of listbox




Re: Windows Forms Designer Email validation control or code for VB.Net 2005.

raj_login

listbox created