Email Tools
fnEmailIsValid ( text )
This function checks for a few common problems with email addresses and returns a 1 or 0 depending on whether or not a submitted block of text passes its tests.
Note that the function makes use of the fnEmailTLDs (Top Level Domains) function.
The function isn meant to be exhaustive: It is still entirely possible to enter an invalid email address; we encourage you to add further conditions to the case function that handles testing.
Also note that the function as written returns a 1 or 0. Using the fnErrorHandler (discussed later in this chapter), you could derive more information from the function when an error condition existed. We wrote this as a Case() test rather than one long concatenated series of tests joined by and operators to explicitly test for each error and allow for the possibility of adding more error handling logic.
Examples:
fnEmailIsValid ( "kathiel@soliantconsulting.com" ) returns 1.
fnEmailIsValid ( "kathielsoliantconsulting.com" ) returns 0.
fnEmailIsValid ( "kathiel@soliant@consultingcom" ) returns 0.
Code:
// tests for valid email address formatting and domain // dependencies: fnEmailTLDs // input: text ( presumably an email address ) // output: 1 or 0 Let ([ lengthText = Length ( text ); positionAt = Position ( text; "@"; 1; 1 ); positionLastDot = Position ( text; "."; lengthText; -1 ); validCharacters = ".0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; userBlock = Left ( text; positionAt - 1 ); domainBlock = Right ( text; lengthText - PositionAt ); topLevelDomain = Right ( text; lengthText - positionLastDot ); errorCondition = Case ( lengthText < 1; 0; // text parameter is empty positionAt = 0; 0; // no @ symbol positionLastDot = 0; // no dot Filter ( userBlock; validCharacters ) serBlock; 0; //invalid chars in user block Filter ( domainBlock; validCharacters ) domainBlock; 0; // invalid chars in domain block PatternCount ( fnEmailTLDs; topLevelDomain & "¶" ) < 1; 0; // top level domain not recognized 1 // if no error condition is met, return 1. ) ]; errorCondition )
fnEmailTLDs ()
This function serves as a system constant (we discuss that term later in the chapter) and holds simply a value list of top-level domains. It is easy to keep the list up-to-date in this form and prevents developers from having to enter this rather unwieldy block of information in more than this one place (or within a larger, more complex function).
Notice that the fnEmailIsValid function requires that a return carriage follow each domain.
Code:
// function contains a text block of return-delimited list of top level domains. "ac ad ae aero //other values removed to save space. Please refer to the electronic files included with this book for a complete listing. zm zw "
Категории