js検証メールフォーマット
2433 ワード
"</span><span style="color:#800000;">text/javascript</span><span style="color:#800000;">"</span>><span style="color:#000000;">
function validate_email(field, alerttxt) {
with (field) {
apos </span>= value.indexOf(<span style="color:#800000;">"</span><span style="color:#800000;">@</span><span style="color:#800000;">"</span><span style="color:#000000;">)
dotpos </span>= value.lastIndexOf(<span style="color:#800000;">"</span><span style="color:#800000;">.</span><span style="color:#800000;">"</span><span style="color:#000000;">)
alert(apos);
alert(dotpos);
</span><span style="color:#0000ff;">if</span> (apos < <span style="color:#800080;">1</span> || dotpos - apos < <span style="color:#800080;">2</span><span style="color:#000000;">)
{ alert(alerttxt); </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;"> }
</span><span style="color:#0000ff;">else</span> { <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span><span style="color:#000000;"> }
}
}
function validate_form(thisform) {
with (thisform) {
</span><span style="color:#0000ff;">if</span> (validate_email(email, <span style="color:#800000;">"</span><span style="color:#800000;"> !</span><span style="color:#800000;">"</span>) == <span style="color:#0000ff;">false</span><span style="color:#000000;">)
{ email.focus(); </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;"> }
}
}
</span>
「XXXX.httm」οnsubmit=「return validatemo(this)」Email:「text」name=「email」size=「30」/>
「submit」value=「Submit」/>
転載先:https://www.cnblogs.com/dreamflycc/archive/2013/01/25/2876652.html