<form action="<%=path%>/reg.do" method="post">
用户:<input type="text" name="uname"><span>${err }</span><span>${err1 }</span><br>
密码:<input type="text" name="password"><span>${err2 }</span><br>
<input type="submit" value="注册">
</form>
@RequestMapping("reg.do")
public String reg(User user,Model model){
User u = ms.getUser(user);
if(u !=null){
model.addAttribute("err", "用户名已存在");
return "reg";
}else if(!user.getUname().matches("^[\\u4e00-\\u9fa5]+$")){
model.addAttribute("err1","用户名只能是中文");
return "reg";
}else if(!user.getPassword().matches("^[0-9]{1,6}$")){
model.addAttribute("err2", "密码只能是数字并且不能超过6位");
return "reg";
}else{
int i = ms.addUser(user);
if(i > 0){
return "login";
}else{
return "reg";
}
}
}
crud注册时正则判断用户名和密码
最新推荐文章于 2023-01-04 15:48:19 发布