// Rejects: empty strings or strings full of blanks, // strings without @ or without . (dot) // Rejects: A@, @B, A@B, .A@B, A@B., A@.B // Accepts: A@B.C, A.B@C.D function ValidEmail(s) { var Count; var s2; // empty or blank email if (EmptyString(s) == true) return (false); // email without @ if (s.indexOf('@') == -1) return (false); // email with @ as the 1st char if (s.indexOf('@') == 0) return (false); // email with @ as the last char if ((s.indexOf('@')+1) == s.length) return (false); // email without . if (s.indexOf('.') == -1) return (false); // email with . as the 1st char if (s.indexOf('.') == 0) return (false); // email with . as the last char if ((s.indexOf('.')+1) == s.length) return (false); // Now look for the first . after the first @ // s2 = string after the first @ s2=s.substring(s.indexOf('@')+1,s.length); // email without a dot after the first @ if (s2.indexOf('.') == -1) return (false); // email dot right after the first @ if (s2.indexOf('.') == 0) return (false); return (true); } function EmptyString(s) { var Count; var Nblank = 0; if (s.length == 0) return (true); // empty string // count the number of blank chars for (Count = 0; Count < s.length; Count++) { if (s.charAt(Count) == " ") Nblank++; } if (Nblank == s.length) return (true); else return (false); }