VBA Validate_Email_Address with REGex

Sub Validate_Email_Address() Dim objRegExp As New RegExp Dim blnIsValidEmail As Boolean Dim rowLooper As Long 'Activate Microsoft VBScript Regular Expressions 5.5 For rowLooper = 2 To ActiveSheet.UsedRange.Rows.Count objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$" blnIsValidEmail = objRegExp.test(Range("C" & rowLooper).Value) '<===============EMAIL ADDRESS TO TEST============== Range("D" & rowLooper).Value = blnIsValidEmail '<===============RESULTS============== Next MsgBox "Done" End Sub ------SQL--- AND allEmails NOT LIKE '%_@_%.__%' --AND PATINDEX('%[^A-z0-9._-]%@%.%',AllEmails) <> 0

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.