1、首先了解什么是Validatebox
简单的讲,Validatebox的功能是起校验作用,例如若通过Validatebox将类型设置为E-mail,那么Validatebox会判断你输入的格式,输入必须输入E-mail格式,否则会提醒报错
2、举个简单的例子,也可以查看easy-ui的API,url:http://www.jeasyui.net/plugins/167.html
例子1:只能输入email类型
<span style="white-space:pre"> </span><input id="vv" class="easyui-validatebox" data-options="required:true,validType:'email'">
例子2:检查新密码与第二次输入的密码是否相同
<span style="white-space:pre"> </span><input id="pwd" name="pwd" type="password" class="easyui-validatebox" data-options="required:true">
<span style="white-space:pre"> </span><input id="rpwd" name="rpwd" type="password" class="easyui-validatebox"
<span style="white-space:pre"> </span> required="required" validType="equals['#pwd']">
3、在struts中,通过action中的数据,判断新增的名字(以姓名为例)是否存在,若存在,则不能添加,实现姓名的验证
前台:
<span style="white-space:pre"> </span><tr>
<td><b>姓 名:</b></td>
<td>
<input id="userName" name="yusers.name" class="easyui-textbox" data-options="required:true"
validType="remote['${ctx}/json/CheckName.action','userNameChk']" invalidMessage="用户名已存在!" />
</td>
</tr>
action:
<span style="white-space:pre"> </span>//检查是否重复
public String CheckName() throws Exception{
PrintWriter out = getResponse().getWriter();
StringBuilder hql=new StringBuilder(
"from Yusers where name = '" + userNameChk + "'" );
if( total>0){
out.print(false);
}else{
out.print(true);
}
return null;
}
效果: