' Validates an email address
' Returns True if valid, False if invalid ' ' Example: ' If IsValidEmail(Value:="x@y.com", MaxLength:=255, IsRequired:=True) then ... Function IsValidEmail(ByRef Value As String, Optional ByVal MaxLength As Long = _ 255, Optional ByVal IsRequired As Boolean = True) As Boolean On Error GoTo ErrorHandler IsValidEmail = True Value = Trim$(Value) If IsRequired And Len(Value) = 0 Then IsValidEmail = False End If If Len(Value) > MaxLength Then IsValidEmail = False End If If Len(Value) > 0 Then If InStr(1, Value, "@") = 0 Then IsValidEmail = False End If End If ExitMe: Exit Function ErrorHandler: Err.Raise Err.Number, "IsValidEmail", Err.Description End Function |