473,795 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating emails

Hi

I have this problem that client users enter emails incorrectly due to type
and either the domain name is invalid (Microsot.com instead of
Microsoft.com) or the syntax of the email (user'domain.co m instead of
us**@domain.com). Is there any way to ensure a) email syntax is correct and
b) reverse dns or any other check to highlight invalid domain names?

Thanks

Regards
Sep 2 '06 #1
4 1830


public const string
RegexValidEMail = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
static public bool IsValidRegexVal idEMail (string ValueToTest)
{ return Regex.IsMatch(V alueToTest, RegexValidEMail ); }
Sep 2 '06 #2
That's C#. Translated to VB:

Imports System.Text.Reg ularExpressions

Public Function IsValidRegexVal idEMail(ByVal ValueToTest As String) As
Boolean
Const RegexValidEMail As String =
"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"
IsValidRegexVal idEMail = Regex.IsMatch(V alueToTest, RegexValidEMail )
End Function

Regular expression doesn't check the length of the address and may miss
few valid addresses with special chars. See
http://en.wikipedia.org/wiki/E-mail_address

Checking domains requires a third party component as far as I know. If
someone
knows a way how to do it in VB I'd like to know too.

In the first place checking domains (or MX records) may not be feasible. It
tends to
be slow unless you have only a few email address.

- Timo
<ne************ ***@charter.net wrote in message
news:Vc******** ********@newsfe 04.lga...
>

public const string
RegexValidEMail =
@"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
static public bool IsValidRegexVal idEMail (string ValueToTest)
{ return Regex.IsMatch(V alueToTest, RegexValidEMail ); }

Sep 2 '06 #3
"John" <Jo**@nospam.in fovis.co.ukschr ieb:
I have this problem that client users enter emails incorrectly due to type
and either the domain name is invalid (Microsot.com instead of
Microsoft.com) or the syntax of the email (user'domain.co m instead of
us**@domain.com). Is there any way to ensure a) email syntax is correct
and b) reverse dns or any other check to highlight invalid domain names?
Parsing Email Addresses using an RFC822 Compliant Address Validator
<URL:http://www.codeproject .com/csharp/RFC822Validator .asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Sep 2 '06 #4
I'm not an expert with email, but, here is how I'd do it...

Step1] Do the RegEd code to check format of email.
Step2] I'd figure out a way to test if the email address is valid by sending
it and checking the receipt of the email (if this can be done in .net or via
your email service).
Step3] If the email is valid then add it to a database table.
Step4] On all future email send commands then do a lookup against the
database table for the email. If email has been previously sent with out
issues then all user to keep going and send the email. Otherwise, kick up a
message box asking user if they have a valid email address.

You could also do a check against your global address book in your email
system (Outlook) or in Active Directory. If your using Acitve Directory
then you can use .net code to see your network wide addresses if you have
admin authority.

Hope this helps! JerryM
Oct 13 '06 #5

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

Similar topics

6
5803
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed to leave the textbox without entering the right information. Is there a way to determine which other control was clicked in the validating event of the textbox? Thanks
2
13182
by: orekinbck | last post by:
Hi There I have spent alot of time trying to get a masked text box to validate e-mails, but with no success. Mainly because I can't figure out how to account for the wide variety of different e-mail addresses, for example: billwallis@hta.com bill.wallis@hta.com billwallis@hta.com.au bill.wallis@hta.com.au
11
1345
by: tshad | last post by:
I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth) I want to be able to test to make sure that the dates are valid and the the From dates are < the To dates. When I add the records to the database, I typically use something like: FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue I also have other validators on the screen for emails and required fields.
0
1554
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around with my code I figured out how to get it to work. I am not sure what the reason behind it is but it...
2
2129
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
0
2441
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
3
2040
by: oopaevah | last post by:
Hello To prevent scross site scripting I am validating each value in the Request.Params collection against the following regular expression : ^*$ This only allows the following characters : a-Z
4
2768
by: SAL | last post by:
I am using a RegularExpressionValidator control on my ASP page, and I have the ValidationExpression property set to "Internet E-mail Address". The email address is valiated when the user puts in a email addess in the TextBox. This works fine until I have multiple email addresses. How can I validate multiple e-mail addresses seperated by a "," or ";"? The following ValidationExpression will validate up to 2 email addresses but not...
1
1299
by: John | last post by:
Hi I have this problem that client users enter emails incorrectly due to type and either the domain name is invalid (Microsot.com instead of Microsoft.com) or the syntax of the email (user'domain.com instead of user@domain.com). Is there any way to ensure a) email syntax is correct and b) reverse dns or any other check to highlight invalid domain names? Thanks
0
3438
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
Like many people, I normally use Yahoo! Mail via the web and like to keep all my emails stored on the Yahoo! server. However sometimes I can’t get access to a PC/the web and I download my emails to a PDA/palmtop via POP3. The PDA uses Windows Mobile software. Since using the PDA, I have had the problem of emails disappearing from the Yahoo! server. However I think I now understand how to avoid this. It seems that Windows Mobile is...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.