473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Validate Email. RegEx. Need Help.

Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel

Nov 19 '05 #1
4 2200
http://www.regexlib.com/Search.aspx?k=email

I have implemented one of their expressions - it works great.


"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:ua**************@TK2MSFTNGP15.phx.gbl...
Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel

Nov 19 '05 #2

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:ua**************@TK2MSFTNGP15.phx.gbl...
Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel

Try something like this...

Dim x As String = TextBox1.Text

Const pattern As String = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Dim theRegEx As New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compil ed)

If theRegEx.IsMatch(x) Then

Label1.Text = "Valid email"

Else

Label1.Text = "Bad email address"

End If

Watch out for line wrap in the above.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 19 '05 #3
Thanks Peter,

It was exactly that what I was looking for.
I didn't know how to use the Regular Expressions.
Now I know.

Thanks Once Again,
Miguel

"Peter van der Goes" <p_**********@toadstool.u> wrote in message
news:p_**********@toadstool.u:
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:ua**************@TK2MSFTNGP15.phx.gbl...
Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel


Try something like this...

Dim x As String = TextBox1.Text

Const pattern As String = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Dim theRegEx As New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compil ed)

If theRegEx.IsMatch(x) Then

Label1.Text = "Valid email"

Else

Label1.Text = "Bad email address"

End If

Watch out for line wrap in the above.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.


Nov 19 '05 #4
http://samples.gotdotnet.com/quickstart/howto/

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my
variable is valid. I found many examples of how to use ASP.NET
validation in aspx code but I can't find examples on how to use RegEx
in my VB.Net code.

Can someone help me out?

Thank You,
Miguel


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Henrik Nyberg | last post by:
Here's a small method for validating email in C#. It may save you some time.. public static bool IsValidEmailAddress(string sEmail) { if (sEmail == null) { return false; } int nFirstAT =...
2
by: Byron | last post by:
All I am trying to do is use Regex.IsMatch to validate that a string is either empty, or exactly 4 characters (digits) in length. In other words, the strings, "", and "1234" should pass, whereas...
7
by: Ali-R | last post by:
Hi all, I am getting a CSV file like this from our client: "C1","2","12344","Mr","John","Chan","05/07/1976"......... I need to validate **each filed value** against a set of rules ,for...
4
by: luca.milan | last post by:
Hi, have a problem with this regex: ^(?<target>order|customer)@(?<action>view|save|delete)$ With this options: order@view, order@save, order@delete or customer work fine, but with the target:...
1
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to validate an email address entered into an input textbox. Does anyone have any code for this? -- Michael Bragg, President...
23
by: codefire | last post by:
Hi, I am trying to get a regexp to validate email addresses but can't get it quite right. The problem is I can't quite find the regexp to deal with ignoring the case james..kirk@fred.com, which...
5
by: Seb | last post by:
Hi, I am trying to find the right regular expression which would only validate a URL with a given number of folders. Example: http://www.abc.com/folder/page.htm --Valid (4 slahes)
2
by: Neo Geshel | last post by:
Greetings, I have a form with a telephone field. It is very specific, as it has four text boxes - the country code, area code, prefix and suffix. I can validate each of them individually, but...
20
numberwhun
by: numberwhun | last post by:
Hello everyone! I am still learning (TONS every day) and having an absolute blast. Unfortunately, I have an issue that is puzzling and bewildering me. Seeing as how the best way to learn is to...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.