Validate email on customer contacts

Vantage 8.03.407 Progress

I worked on this today and I was so happy with the results I wanted
to share it with everyone.

We started using our customer contacts to send out automated emails
for things like shipping notifications. I wanted to make sure that
the email addresses that were entered were at least somewhat valid.
Below is the custom code I created to validate email address as they
are entered for customer contacts.

You will want to put the Imports statement at the top of you code
with all the other imports. You will also have to replace the
getNativeControlReference code with the EpiGuid code of the txtEmail
field found on the Contacts/Datail sheet.

**********************************************************

Imports System.Text.RegularExpressions

Private Sub CustCnt_BeforeFieldChange(ByVal sender As object, ByVal
args As DataColumnChangeEventArgs) Handles
CustCnt_Column.ColumnChanging
'// ** Argument Properties and Uses **
'// args.Row("[FieldName]")
'// args.Column, args.ProposedValue, args.Row
'
'Add Event Handler Code
'
Dim EmailTB as EpiTextBox = CType(csm.getNativeControlReference
("f354301a-2958-4772-ab8a-f536d8c4bc9b"),EpiTextBox)
Select Case args.Column.ColumnName

Case "EMailAddress"
if (len(args.ProposedValue)>0) AND NOT (EmailAddressCheck
(args.ProposedValue))
msgbox(args.ProposedValue & " is not a
valid email address. Email address has not been changed!")
EmailTB.Text = args.row("EMailAddress")
args.ProposedValue = args.row("EMailAddress")
End If
Case Else

End Select

End Sub

Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
Dim pattern As String = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*"
Dim emailAddressMatch As Match = Regex.Match(emailAddress,
pattern)
If emailAddressMatch.Success Then
EmailAddressCheck = True
Else
EmailAddressCheck = False
End If
End Function