cbseven / fm_mailchimp

A FileMaker Adapter for the Mailchimp API v3
3 stars 1 forks source link

Email validation does not check TLD #10

Open processIT-MarK opened 1 week ago

processIT-MarK commented 1 week ago

Hi

Thanks for sharing fm_mailchip. I have noticed that you are using CF to check the email (mcpriv - validate email - https://www.briandunning.com/cf/972), which (funny fact) I asked in 2018 to update regarding TLD (characters after the last dot - needs to has at least 2 characters).

Can you take into consideration updating the function (I already posted the solution in CF 972), or maybe use another function that covers this functionality? (https://www.briandunning.com/cf/2487)

Regards

processIT-MarK commented 1 week ago

Here is a udpated function, it seems that my update does not go throught at https://www.briandunning.com/cf/972

Let ( [
    _alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
    _email = Trim (_email ) ;
    _posAt = Position ( _email; "@" ; 1 ; 1 );
    dotPosition = Position(_email; "."; _posAt; 1);
    tldLength = Length(_email) - dotPosition;
    result =    Filter ( _email ; _alphanum & "_-@.!#$%&'*+-/=?^_`{|}~" ) = _email   // There are no invalid characters.
    and PatternCount ( _email ; "@" ) = 1   // There is only one @ symbol.
    and Length ( Filter ( Left ( _email ; 1 )
                & Middle ( _email ; _posAt - 1 ; 3 )
                & Right ( _email ; 1 ) ; _alphaNum ) ) = 4  // First and last character are alphanumeric.
    and not PatternCount ( _email ; ".." )
    and Position ( _email ; "." ; _posAt + 2 ; 1 ) and
    //Check TLD lengt, minumum 2 characters
    _posAt > 1 and
    dotPosition > _posAt + 1 and
    tldLength ≥ 2

] ;
result
)