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.
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.
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.
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 ThenMessageBox.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
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.
imports.system.text.regularexpressions
]
frm:lucky(btech)
what is web page desgine
means of listbox
listbox created