1. 页面:join.jsp
<tr>
<td align="right">Email:</td>
<td align="left"><input id="email" type="text" name="email" value="" class="joinField"><br />
<FONT color=red><span id="error_email"></span></FONT></td>
</tr>
2. common.js
//email check
function emailCheck () {
var emailStr = document.getElementById("email").value;
var emailPat = /^(.+)@(.+)$/;
var matchArray = emailStr.match(emailPat);
if (matchArray == null) {
document.getElementById("email").focus();
document.getElementById("error_email").innerHTML = "email is wrong !";
return false;
}else{
return true;
}
}
3. join.jsp提交按钮的时候,在button上面写事件。
οnclick="return emailCheck();"
在cyberage项目中的注册JS判断:
function registerCheckField () {
var usernameValue = document.getElementById("username").value;
var passwordValue = document.getElementById("password").value;
usernameValue = usernameValue.replace(/\s/gi,"");
passwordValue = passwordValue.replace(/\s/gi,"");
var emailStr = document.getElementById("email").value;
var emailPat = /^(.+)@(.+)$/;
var matchArray = emailStr.match(emailPat);
if(usernameValue !== "" && passwordValue !== ""){
document.getElementById("error_username").innerHTML = "";
document.getElementById("error_password").innerHTML = "";
if (matchArray == null) {
document.getElementById("email").focus();
document.getElementById("error_email").innerHTML = "email format is incorrect !";
return false;
}else{
loginForm.action="./openid.servlet?signup=now";
loginForm.sumbit();
return true;
}
}else if(usernameValue == "" && passwordValue == ""){
document.getElementById("username").focus();
document.getElementById("error_info").innerHTML = "";
document.getElementById("error_username").innerHTML = "username can't be null !";
document.getElementById("error_password").innerHTML = "password can't be null !";
return false;
}else if(usernameValue !== "" && passwordValue == ""){
document.getElementById("password").focus();
document.getElementById("error_info").innerHTML = "";
document.getElementById("error_username").innerHTML = "";
document.getElementById("error_password").innerHTML = "password can't be null !";
return false;
}else if(passwordValue !== "" && usernameValue == ""){
document.getElementById("username").focus();
document.getElementById("error_info").innerHTML = "";
document.getElementById("error_password").innerHTML = "";
document.getElementById("error_username").innerHTML = "username can't be null !";
return false;
}
}
$(function(){
reg=/^[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/;
$("#signupForm").submit(function(){
if($("#username").val().replace(/\s/gi,"")=="")$("#un").html("<font color=\"red\">require field!!</font>");else $("#un").html("");
if($("#password").val().replace(/\s/gi,"")=="")$("#psw").html("<font color=\"red\">require field!!</font>");else $("#psw").html("");
if($("#email").val()=="")$("#em").html("<font color=\"red\">require field!!</font>");
else if(!reg.test($("#email").val()))$("#em").html("<font color=\"red\">invalid email address!!</font>");
else $("#em").html("");
if(!reg.test($("#email").val())||$("#username").val()==""||$("#password").val()==""||$("#email").val()==""){
return false;
}
});
})