Domino Code Fragment

Code Name*
Format E-mail Addresses
Date*
07/08/2000
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.
Description*
Most Web sites that collect user contact information require users to enter their e-mail addresses. The formatEmail function checks to make sure an e-maill address has been enetered in the correct format - if not, it returns an empty string.
Type*
JavaScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

function formatEmail(inputstring) {
        fixed = "";
        exts = ".com.edu.gov.mil.net.int.org";
        badchars = " /`!#$%^&*()+{}[]|\\:;'"<>,?";
        for (x = 0; x < inputstring.length; x++) {
                ch = inputstring.charAt(x);
                if (badchars,indexOf(ch) == -1) { Fixed = Fixed + ch.toLowerCase(); }
        }
        if (upperBound(Fixed, "@") !=2) { Fixed = ""; }
        if (Fixed.indexOf("@") == 0) { Fixed = ""; }
        before = getDelimitedSubstring(Fixed, 1, "@");
        after = Fixed.substring(Fixed.length - 4, Fixed.length);
        if (before == "") { Fixed = ""; }
        if (after.length != 4) { Fixed =""; }
        else {
                ext  = Fixed.substring(Fixed.length - 4, Fixed.length);
                if (exts.indexOf(ext) == -1) { Fixed = ""; }
        }
        return Fixed;
}