<input name=email class=clear_input id=email maxlength="50" value="<%=email%>" onBlur="javascript:checkEnglish()"/>
<span id=reg_email_error style="DISPLAY: none">ReadyState</span>
function checkEnglish(){
if (!CheckIfEnglish(document.insertForm.email.value )) {
alert("请输入数字,字母和下划线!");
document.insertForm.email.value="";
document.insertForm.email.focus();
return false;
}
else {
doCheck();
return true;
}
}
function CheckIfEnglish( String ){
var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_";
var i;
var c;
if(String.charAt( 0 )=='-')
return false;
if( String.charAt( String.length - 1 ) == '-' )
return false;
for( i = 0; i < String.length; i ++ ){
c = String.charAt( i );
if (Letters.indexOf( c ) < 0)
return false;
}
return true;
}
ajax.js
//定义XMLHttpRequest对象实例
var http_request = false;
//定义可复用的http请求发送函数
function send_request(method,url,content,responseType,callback) {//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
if(responseType.toLowerCase()=="text") {
//http_request.onreadystatechange = processTextResponse;
http_request.onreadystatechange = callback;
}
else if(responseType.toLowerCase()=="xml") {
//http_request.onreadystatechange = processXMLResponse;
http_request.onreadystatechange = callback;
}
else {
window.alert("响应类别参数错误。");
return false;
}
// 确定发送请求的方式和URL以及是否异步执行下段代码
if(method.toLowerCase()=="get") {
http_request.open(method, url, true);
}
else if(method.toLowerCase()=="post") {
http_request.open(method, url, true);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
else {
window.alert("http请求类别参数错误。");
return false;
}
http_request.send(content);
}
// 处理返回文本格式信息的函数
function processTextResponse() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
//alert(http_request.responseText);
alert("Text文档响应。");
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
//处理返回的XML格式文档的函数
function processXMLResponse() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
//alert(http_request.responseXML);
alert("XML文档响应。");
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
function doCheck() {
var f = document.forms[0];
if(f.email.value!="") {
document.getElementById("reg_email_error").innerHTML = "系统正在处理您的请求,请稍后。";
send_request("GET","checkUsername.jsp?email="+f.email.value,null,"text",showFeedbackInfo);
}
else {
document.getElementById("reg_email_error").innerHTML = "请输入用户名称。";
}
}
checkUsername.jsp
<%@ page contentType="text/html; charset=gbk"%>
<%@ page import="com.beyoung.blog.hql.admin.huiyuangguanli.HuiyuangguanliHql" %>
<%@ page import="com.beyoung.blog.bean.Huiyuangguanli" %>
<%@ page import="com.beyoung.blog.util.strDate.PubFun" %>
<%
String name=request.getParameter("email");
name=PubFun.toGBK(name);
System.out.println(name);
System.out.println(" :"+HuiyuangguanliHql.getHuiyuangguanliHql().getHuiyuangguanliKey(name));
if(!HuiyuangguanliHql.getHuiyuangguanliHql().getHuiyuangguanliKey(name)){
out.println("<font color='#FF0000'>用户名称["+name+"]已占用!</font>");
}
else{
out.println("<font color='#088EOF'>用户名称["+name+"]尚未被注册,您可以继续。</font>");
}
%>