JavaScript verification Email (3 methods), javascriptemail
Today, we recommend three JavaScript verification Email methods for you, hoping to help you learn them.
First: Verify the email format in javascript
<SCRIPT LANGUAGE=javascript RUNAT=Server>function isEmail(strEmail) {if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)return true;elsealert("oh");}</SCRIPT><input type=text onblur=isEmail(this.value)>
Method 2: use Javascript to verify that email is entered correctly
<Html>
Third: js verification Email
Function char_test (chr) // character detection function {var I; var smallch = "abcdefghijklmnopqrstuvwxyz"; var bigch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (I = 0; I <26; I ++) if (chr = smallch. charAt (I) | chr = bigch. charAt (I) return (1); return (0);} function spchar_test (chr) // number and special character detection function {var I; var spch = "_-. 0123456789 "; for (I = 0; I <13; I ++) if (chr = spch. charAt (I) return (1); return (0);} function email_test (str) {var I, flag = 0; var at_symbol = 0; // "@" detected position var dot_symbol = 0; // ". "detection location if (char_test (str. charAt (0) = 0) return (1); // the first character must contain the letter for (I = 1; I <str. length; I ++) if (str. charAt (I) = '@') {at_symbol = I; break;} // check the position of "@" if (at_symbol = str. length-1 | at_symbol = 0) return (2); // No email server domain name if (at_symbol <3) return (3 ); // The account has less than three characters if (at_symbol> 19) return (4); // The account has more than 19 characters for (I = 1; I <at_symbol; I ++) if (char_test (str. charAt (I) = 0 & spchar_test (str. charAt (I) = 0) return (5); for (I = at_symbol + 1; I <str. length; I ++) if (char_test (str. charAt (I) = 0 & spchar_test (str. charAt (I) = 0) return (5); // other special characters for (I = at_symbol + 1; I <str. length; I ++) if (str. charAt (I) = '. ') dot_symbol = I; for (I = at_symbol + 1; I <str. length; I ++) if (dot_symbol = 0 | dot_symbol = str. length-1) // check whether ". "to determine whether the server name is legal return (6); return (0); // The Mail name is legal}
The above is the JavaScript verification Email method. Have you learned it?