注册页面账号验证

 

1.首先用ajax传页面上的值,在账号<input>后面要记得写上<span id="er"></span>,不然不会提示账号能不能用,有没有被注册过

 

<script type="text/javascript">
function home(){
window.location.href="view/login.jsp";
}
$(function(){

//账号验证
$("#Account").blur(function(){

var Account=$("#Account")[0].value ;

$.ajax({
url : 'validation.do',
data : {
Account :Account,
},
type : "post",

success : function(result) {

if (result.success) {
$("#er").text("账号可以注册")
} else {
$("#er").text("此账号已被注册");};
},

});

});
});

$().ready(function() {
// 提交时验证表单
var validator = $("#regform").validate({
errorPlacement: function(error, element) {

$( element )
.closest( "form" )
.find( "label[for='" + element.attr( "id" ) + "']" )
.append( error );
},
rules: {
Account: {
required:true,
minlength:3,
maxlength:20
},
Password: {

required:true,
minlength:6,
maxlength:20
},

Enter_the_password_again: {
equalTo:"#Password"
},

Phonenumber:{
digits:true,
required: true,
minlength:11,
maxlength: 11
},
},


messages: {
Account: {
required: "请输入账号!",
minlength: " 请输入3——20个字",
maxlength: " 请输入3——20个字"
},
Password: {
required: "密码不能为空",
minlength: " 请输入6——20个字",
maxlength: " 请输入6——20个字"
},
Enter_the_password_again: {
equalTo: "两次密码输入不一致"
},
Phonenumber:{
digits:"只能输入数字",
required: "请输入您的手机",
minlength: "请输入正确的手机号码格式",
maxlength: "请输入正确的手机号码格式"
},
}
});

$(".cancel").click(function() {
validator.resetForm();
});
});
</script>

</head>

<body>
<form method="post" id="regform">

<table align = "center" border="1" style="border-collapse: collapse;">
<tr>
<td colspan="2">代理注册</td>
</tr>
<tr>
<td>账号:</td>
<td><input type="text" name="Account" id="Account"/><span id="er"></span>
<label for="Account"></label>
</td>
</tr>
<tr>
<td>密码:</td>
<td><input type="text" name="Password" id="Password"/>
<label for="Password"></label>
</td>
</tr>
<tr>
<td>请再输入一次密码:</td>
<td><input type="text" name="Enter_the_password_again" id="Enter_the_password_again" />
<label for="Enter_the_password_again"></label>
</td>
</tr>
<tr>
<td>常用手机号码:</td>
<td><input type="text" name="Phonenumber" id="Phonenumber"/>
<label for="Phonenumber"></label>
</td>
</tr>
<tr>
<td>真实姓名:</td>
<td><input type="text" name="Realname" /></td>
</tr>

<tr>
<td>身份证号码:</td>
<td><input type="text" name="Idcardnumber" /></td>
</tr>
<tr>
<td>代理地区:</td>
<td>
<select id="Province" name="Province"></select>
<select id="City" name="City"></select>
<select id="Area" name="Area"></select>
<script type="text/javascript">
addressInit('Province', 'City', 'Area');
</script>
</td>
</tr>
<tr>
<td>公司名称:</td>
<td><input type="text" name="Nameofcompany" /></td>
</tr>
<tr>
<td>推荐人ID:</td>
<td><input type="text" name="Referees" /></td>
</tr>
<tr>
<td>代理头像:</td>
<td><input type="text" name="Agencyhead" /></td>
</tr>

<tr>
<td>代理法人照片(手持身份证):</td>
<td><input type="text" name="Photoagencyasalegalperson" /></td>
</tr>
<tr>
<td>营业执照:</td>
<td><input type="text" name="Thebusinesslicense" /></td>
</tr>

<tr>
<td>营业执照副本:</td>
<td><input type="text" name="Duplicateofbusinesslicense" /></td>
</tr>
<tr>
<td>银行开户许可证:</td>
<td><input type="text" name="Thebankopensanaccountlicence" /></td>
</tr>
<tr>
<td>父级代理ID:</td>
<td><input type="text" name="Pid" /></td>
</tr>
</tr>
<tr>
<td>请填写密保:</td>
</tr>
<tr>
<td>密保问题一:</td>
<td>
<select name="Encrypted_problem_one">
<option value ="1">你父亲的名字叫什么?</option>
<option value ="2">你母亲的名字叫什么?</option>
<option value="3">你配偶的名字叫什么?</option>
</select>
</td>
</tr>
<tr>
<td>密保答案:</td>
<td><input type="text" name="Encrypted_answers_one" /></td>
</tr> <tr>
<td>密保问题二:</td>
<td>
<select name="Encrypted_problem_two">
<option value ="1">你父亲的名字叫什么?</option>
<option value ="2">你母亲的名字叫什么?</option>
<option value="3">你配偶的名字叫什么?</option>
</select>
</td>
</tr>
<tr>
<td>密保答案:</td>
<td><input type="text" name="Encrypted_answers_two" /></td>
</tr>
<tr>
<td>密保问题三:</td>
<td>
<select name="Encrypted_problem_three">
<option value ="1">你父亲的名字叫什么?</option>
<option value ="2">你母亲的名字叫什么?</option>
<option value="3">你配偶的名字叫什么?</option>
</select>
</td>
</tr>
<tr>
<td>密保答案:</td>
<td><input type="text" name="Encrypted_answers_three" /></td>
</tr>
<tr>
<td class="tdstyle" colspan="2">
<a href="javascript:void(0);" class="easyui-linkbutton" onclick="login();">注册</a>
<a href="javascript:void(0);" class="easyui-linkbutton" onclick="home();">返回登陆</a>
</td>
</tr>
</table>
</form>
</body>

 

2,用ajax把值传给验证的Controller,注解都要打上。

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.maicor.service.ValidationService;

@Controller("ValidationController")
public class ValidationController {

@Resource
ValidationService validationService;

@RequestMapping(value="validation")
@ResponseBody
public Map<String, Object> validation(String Account) throws Exception {

Map<String, Object> result=validationService.add(Account);


return result;
}
}

 

3,然后Controller的值再传给验证的service


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.maicor.dao.ValidationDao;


@Service("ValidationService")
public class ValidationService {

@Resource
private ValidationDao validationDao;

public Map<String, Object> add(String Account) throws Exception {//查找账号进行判断
Map<String, Object> map=new HashMap<String, Object>();
try {
if(validationDao.info(Account)>0){

map.put("success", false);
}else{
map.put("success", true);
}

} catch (Exception e) {
e.printStackTrace();
}

return map;

}

}

 

4.还要写个验证的Dao,Dao里面是Jdbc连接数据库的


@Repository("ValidationDao")
public class ValidationDao {
@Autowired
private JdbcTemplate jdbcTemplate;


//搜索输入的账号是否为空,并返回搜索的account对象
public int info(String Account)throws Exception{

String sql="select count(*) from agency where Account=?";

int a=jdbcTemplate.queryForInt(sql,Account);

return a;
}
}

posted @ 2016-11-30 16:26  李科纪  阅读(382)  评论(0编辑  收藏  举报