代碼如下 |
複製代碼 |
if (document.register.email.value.charAt(0)=="." || document.register.email.value.charAt(0)=="@"|| document.register.email.value.indexOf('@', 0) == -1 || document.register.email.value.indexOf('.', 0) == -1 || document.register.email.value.lastIndexOf("@")==document.register.email.value.length-1 || document.register.email.value.lastIndexOf(".")==document.register.email.value.length-1) { alert("電子郵箱格式不正確!"); document.register.email.focus(); return false; } sendRequest("checkemail.asp?email=" + document.register.email.value); if (return_str=="0"){ alert("該郵箱已經存在,請另選一個"); document.register.email.focus(); document.register.email.select(); return false } |
//ajax處理
代碼如下 |
複製代碼 |
var return_str="" xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); function sendRequest(sndStr) { var xmlDom = new ActiveXObject("Msxml2.DOMDocument"); xmlhttp.open("GET", sndStr, false); xmlhttp.onreadystatechange = sendRequest_check; xmlhttp.Send(xmlDom); } //-------------------------------------------------------- function sendRequest_check() { var state = xmlhttp.readyState; var xmlDom = new ActiveXObject("Msxml2.DOMDocument");
if (state == 4) { xmlDom.loadXML(xmlhttp.responseXML.xml); return_str = xmlDom.documentElement.selectSingleNode("//objXML").text; } } |
checkemail.asp檔案你只要接受到使用者的資訊,在資料庫中檢測一下就KO了。