|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Validating emailsHi
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 u***@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 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 IsValidRegexValidEMail (string ValueToTest) { return Regex.IsMatch(ValueToTest, RegexValidEMail); } That's C#. Translated to VB:
Imports System.Text.RegularExpressions Public Function IsValidRegexValidEMail(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})$" IsValidRegexValidEMail = Regex.IsMatch(ValueToTest, 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 <newscorrespond***@charter.net> wrote in message Show quoteHide quote news:Vc6Kg.1342$Xb2.426@newsfe04.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 IsValidRegexValidEMail (string ValueToTest) > { return Regex.IsMatch(ValueToTest, RegexValidEMail); } 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 "John" <John@nospam.infovis.co.uk> schrieb: Parsing Email Addresses using an RFC822 Compliant Address Validator> 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 > u***@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? <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/>
Structures, Classes for storing data
Changing the text of a Command Button using SetWindowText Is Thread.Abort() blocking until Thread has exited? "If" statement asking for integer Stream Appending text to an array of textboxes how to add dynamic tooltip when dragging scrollbar of datagridview what is wrong with this StreamWriter, FileStream throwing uncatchable NullReferenceException Is there a Library or component for creating HTML? |
|||||||||||||||||||||||