1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
<span style="color: #006600;font-style: italic">// 验证电子邮箱</span>
<span style="color: #006600;font-style: italic">// 注:不能给正则表达式加上“引号”</span>
<span style="color: #003366;font-weight: bold">function</span> checkEmail<span style="color: #009900">(</span>obj<span style="color: #009900">)</span> <span style="color: #009900">{</span>
    <span style="color: #003366;font-weight: bold">var</span> _email <span style="color: #339933">=</span> $<span style="color: #009900">(</span><span style="color: #3366CC">"#"</span> <span style="color: #339933">+</span> obj<span style="color: #009900">)</span>.<span style="color: #660066">val</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    <span style="color: #006600;font-style: italic">//var emailRegExp = new RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/);</span>
    <span style="color: #006600;font-style: italic">//var emailRegExp2 = new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);</span>
    <span style="color: #006600;font-style: italic">//var emailRegExp3 = new RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.(?:com|cn)$/);</span>
 
    <span style="color: #003366;font-weight: bold">var</span> reg1 <span style="color: #339933">=</span> <span style="color: #009966;font-style: italic">/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.(?:com|cn)$/</span><span style="color: #339933">;</span>
    <span style="color: #006600;font-style: italic">//var reg2 = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;</span>
 
    <span style="color: #000066;font-weight: bold">if</span> <span style="color: #009900">(</span><span style="color: #339933">!</span>reg1.<span style="color: #660066">test</span><span style="color: #009900">(</span>_email<span style="color: #009900">)</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
        <span style="color: #000066">alert</span><span style="color: #009900">(</span>_email <span style="color: #339933">+</span> <span style="color: #3366CC">"不是有效的email地址,请输入有效的E_mail!"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
        $<span style="color: #009900">(</span><span style="color: #3366CC">"#txtEmail"</span><span style="color: #009900">)</span>.<span style="color: #000066">focus</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    <span style="color: #009900">}</span>
    <span style="color: #006600;font-style: italic">/*if (!reg2.test(_email)) {
        alert(_email + "不是有效的email地址,请输入有效的E_mail!");
        $("#txtEmail").focus();
    }
    if (!emailRegExp.test(_email)) {
        alert(_email + "不是有效的email地址,请输入有效的E_mail!");
        $("#txtEmail").focus();
    }
    if (!emailRegExp2.test(_email)) {
        alert(_email + "不是有效的email地址,请输入有效的E_mail!");
        $("#txtEmail").focus();
    }
    if (!emailRegExp3.test(_email)) {
        alert(_email + "不是有效的email地址,请输入有效的E_mail!");
        $("#txtEmail").focus();
    }
    if (_email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
        alert(_email + "不是有效的email地址,请输入有效的E_mail!");
        $("#txtEmail").focus();
    }*/</span>
<span style="color: #009900">}</span>