下面给一个在Spring 中使用common-validator进行表单验证的小例子
1.POJO:
public class Book {
String id;
String name;
String author;
String price;
public Book(){
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String toString(){
return "\nid: " + id + "\nname: " + name + "\nauthor: " + author + "\nprice: " + price;
}
}
2.Controller, 这个controller要继承自支持validation的controller,最典型的就是SimpleFormController.
public class BookController extends SimpleFormController{
@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
Book book = (Book)command;
System.out.println(book);
return super.onSubmit(request, response, command, errors);
}
}
3.在bean config文件里定义两个bean:validatorFactory,beanValidator(写法参见代码)。
<bean id="validatorFactory" class="org.springmodules.commons.validator.DefaultValidatorFactory">
<property name="validationConfigLocations">
<list>
<value>WEB-INF/spring-validator-rules.xml</value>
<value>WEB-INF/validation.xml</value>
</list>
</property>
</bean>
<bean id="beanValidator" class="org.springmodules.commons.validator.DefaultBeanValidator">
<property name="validatorFactory" ref="validatorFactory"/>
</bean>
4.定义Controller bean: /addBook.do(写法参见代码) 有一点要强调:commandName不可以随便写,比如本例中commandClass是model.Book,:commandName如果写成bookForm会出错。必须写成首字母小写:book.
<bean name="/addbook.do" class="action.BookController">
<property name="commandName" value="book" />
<property name="commandClass" value="model.Book"/>
<property name="formView" value="addbook.jsp" />
<property name="successView" value="addbook.jsp" />
<property name="validator" ref="beanValidator" />
</bean>
5.编写或拷贝 messages.properties.注意以errors.开头的message在显示验证出错的时候会用到。你可以根据具体情况修改语境。以book.XXXX.displayName类似的消息是和具体的form相关的消息。比如book.name.displayName=Book Name这个,在下面validation.xml的book form中使用到则如果书名出错,则会显示Book Name is required.
注意: 该文件要放在classpath下面.而且如果浏览器语言是中文的, 则要把文件名称改为messages_zh_CN.properties.
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.
common.messages.close=Close
book.id.displayName=Id
book.name.displayName=Book Name
book.author.displayName=Author
book.price.displayName=Price
6.配置messageSource
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
7.拷贝或编写spring-validator-rules.xml到WEB-INF.里面定义了一些validator,你也可以自己添加。这个文件我想既然spring使用的是struts验证框架的plag-in, 则struts中有这个文件.
8.编写WEB-INF/validation.xml,这里面定义了一些常量和form 的validation规则。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
<form-validation>
<global>
<constant>
<constant-name>number</constant-name>
<constant-value>^\d+$</constant-value>
</constant>
<constant>
<constant-name>englishName</constant-name>
<constant-value>^[A-Z0-9a-z\s]+$</constant-value>
</constant>
<constant>
<constant-name>invalidCharacter</constant-name>
<constant-value><![CDATA[$%'*+:;<=>?@^_`{|}]]></constant-value>
</constant>
<constant>
<constant-name>invalidDiscussionCharacter</constant-name>
<constant-value><![CDATA[$%'*+;<=>?@^_`{|}]]></constant-value>
</constant>
<constant>
<constant-name>validDiscussionCharacterReguler</constant-name>
<constant-value><![CDATA[^[^${invalidCharacterForFilter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>invalidBulletinBoardCharacter</constant-name>
<constant-value><![CDATA[$<>^`|]]></constant-value>
</constant>
<constant>
<constant-name>validBulletinBoardCharacterReguler</constant-name>
<constant-value><![CDATA[^[^${invalidBulletinBoardCharacter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>invalidEmailCharacter</constant-name>
<constant-value><![CDATA[$%'*+:;<=>?^_`{|}]]></constant-value>
</constant>
<constant>
<constant-name>validCharacterReguler</constant-name>
<constant-value><![CDATA[^[^${invalidCharacter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>validEmail</constant-name>
<constant-value><![CDATA[^[^${invalidEmailCharacter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>defaultDateFormat</constant-name>
<constant-value><![CDATA[MM/dd/yyyy]]></constant-value>
</constant>
<constant>
<constant-name>invalidCharacterForFilter</constant-name>
<constant-value><![CDATA[$%'*:'<=>^`{|}]]></constant-value>
</constant>
<constant>
<constant-name>validCharacterRegulerForFilter</constant-name>
<constant-value><![CDATA[^[^${invalidCharacterForFilter}]*$]]></constant-value>
</constant>
</global>
<formset>
<form name="book">
<field property="id" depends="maxlength,required">
<arg0 key="book.id.displayName" />
<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
</field>
<field property="name" depends="maxlength,required">
<arg0 key="book.name.displayName" />
<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
</field>
<field property="author" depends="maxlength">
<arg0 key="book.author.displayName" />
<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
<var>
<var-name>maxlength</var-name>
<var-value>5</var-value>
</var>
</field>
<field property="price" depends="mask">
<arg0 key="book.price.displayName" />
<arg1 name="number" key="${var:mask}" resource="false" />
<var>
<var-name>mask</var-name>
<var-value>^[0-9]</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
9 写jsp页面也就是刚才在controller中配置的formView。注意用<spring:bind path="book.xxx">绑订字段。用value="<core:out value="${book.id}"/>"输出上次输入的值。在该页引入messages.jsp用于显示出错消息。
<!--addbook.jsp-->
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="WEB-INF/tld/spring-form.tld" prefix="form"%>
<%@ taglib uri="WEB-INF/tld/c-rt.tld" prefix="core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<script type="text/javascript" src=""></script>
<style type="text/css">
</style>
</head>
<body>
<%@ include file="messages.jsp" %>
<form method="post" action="addbook.do">
<spring:bind path="book.id">
<input type="text" name="id" value="<core:out value="${book.id}"/>"/>
</spring:bind>
<spring:bind path="book.name">
<input type="text" name="name" value="<core:out value="${book.name}"/>"/>
</spring:bind>
<spring:bind path="book.author">
<input type="text" name="author" value="<core:out value="${book.author}"/>"/>
</spring:bind>
<spring:bind path="book.price">
<input type="text" name="price" value="<core:out value="${book.price}"/>"/>
</spring:bind>
<input type="submit" value="Google" /><br>
</form>
</body>
</html>
10 写messages.jsp 注意image路径。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="WEB-INF/tld/c-rt.tld" prefix="core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<SCRIPT LANGUAGE=javascript>
function hideMessage() {
if ( messageTR.style.display == "") {
messageTR.style.display = "none";
}
}
</SCRIPT>
<spring:bind path="book.*">
<core:if test="${not empty status.errorMessages}">
<%
if(request.getAttribute("errors") == null){
List errors = new ArrayList();
request.setAttribute("errors",errors);
}
%>
<core:forEach var="error" items="${status.errorMessages}">
<%List errors = ((List)request.getAttribute("errors"));
errors.add(pageContext.getAttribute("error"));
%>
</core:forEach>
</core:if>
</spring:bind>
<core:if test="${not empty errors or not empty messages}">
<table border=0 cellpadding=0 cellspacing=0 width="95%" align="center">
<tr id='messageTR' style="DISPLAY:">
<td align="center">
<core:if test="${not empty errors}">
<core:set var="hasMessage" value="true"/>
<div align="left" class="error fade-ffff00" id="error">
<core:forEach var="error" items="${errors}">
<img src="<%=request.getContextPath()%>/images/iconWarning.gif" alt='Warning' class="icon" />
<core:out value="${error}" escapeXml="false"/><br/>
</core:forEach>
</div>
<core:remove var="errors"/>
</core:if>
<core:if test="${not empty messages}">
<core:set var="hasMessage" value="true"/>
<div align="left" class="message fade-ffff00" id="message">
<core:forEach var="msg" items="${messages}">
<img src="<%=request.getContextPath()%>/images/iconInformation.gif" alt='Information' class="icon" />
<core:out value="${msg}" escapeXml="false"/><br/>
</core:forEach>
</div>
<core:remove var="messages"/>
</core:if>
<core:if test="${hasMessage eq 'true'}"><a href="javascript:hideMessage();"> <spring:message code="common.messages.close"/> </a></core:if>
</td>
</tr>
</table>
</core:if>
1.POJO:
public class Book {
String id;
String name;
String author;
String price;
public Book(){
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String toString(){
return "\nid: " + id + "\nname: " + name + "\nauthor: " + author + "\nprice: " + price;
}
}
2.Controller, 这个controller要继承自支持validation的controller,最典型的就是SimpleFormController.
public class BookController extends SimpleFormController{
@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
Book book = (Book)command;
System.out.println(book);
return super.onSubmit(request, response, command, errors);
}
}
3.在bean config文件里定义两个bean:validatorFactory,beanValidator(写法参见代码)。
<bean id="validatorFactory" class="org.springmodules.commons.validator.DefaultValidatorFactory">
<property name="validationConfigLocations">
<list>
<value>WEB-INF/spring-validator-rules.xml</value>
<value>WEB-INF/validation.xml</value>
</list>
</property>
</bean>
<bean id="beanValidator" class="org.springmodules.commons.validator.DefaultBeanValidator">
<property name="validatorFactory" ref="validatorFactory"/>
</bean>
4.定义Controller bean: /addBook.do(写法参见代码) 有一点要强调:commandName不可以随便写,比如本例中commandClass是model.Book,:commandName如果写成bookForm会出错。必须写成首字母小写:book.
<bean name="/addbook.do" class="action.BookController">
<property name="commandName" value="book" />
<property name="commandClass" value="model.Book"/>
<property name="formView" value="addbook.jsp" />
<property name="successView" value="addbook.jsp" />
<property name="validator" ref="beanValidator" />
</bean>
5.编写或拷贝 messages.properties.注意以errors.开头的message在显示验证出错的时候会用到。你可以根据具体情况修改语境。以book.XXXX.displayName类似的消息是和具体的form相关的消息。比如book.name.displayName=Book Name这个,在下面validation.xml的book form中使用到则如果书名出错,则会显示Book Name is required.
注意: 该文件要放在classpath下面.而且如果浏览器语言是中文的, 则要把文件名称改为messages_zh_CN.properties.
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.
common.messages.close=Close
book.id.displayName=Id
book.name.displayName=Book Name
book.author.displayName=Author
book.price.displayName=Price
6.配置messageSource
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
7.拷贝或编写spring-validator-rules.xml到WEB-INF.里面定义了一些validator,你也可以自己添加。这个文件我想既然spring使用的是struts验证框架的plag-in, 则struts中有这个文件.
8.编写WEB-INF/validation.xml,这里面定义了一些常量和form 的validation规则。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
<form-validation>
<global>
<constant>
<constant-name>number</constant-name>
<constant-value>^\d+$</constant-value>
</constant>
<constant>
<constant-name>englishName</constant-name>
<constant-value>^[A-Z0-9a-z\s]+$</constant-value>
</constant>
<constant>
<constant-name>invalidCharacter</constant-name>
<constant-value><![CDATA[$%'*+:;<=>?@^_`{|}]]></constant-value>
</constant>
<constant>
<constant-name>invalidDiscussionCharacter</constant-name>
<constant-value><![CDATA[$%'*+;<=>?@^_`{|}]]></constant-value>
</constant>
<constant>
<constant-name>validDiscussionCharacterReguler</constant-name>
<constant-value><![CDATA[^[^${invalidCharacterForFilter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>invalidBulletinBoardCharacter</constant-name>
<constant-value><![CDATA[$<>^`|]]></constant-value>
</constant>
<constant>
<constant-name>validBulletinBoardCharacterReguler</constant-name>
<constant-value><![CDATA[^[^${invalidBulletinBoardCharacter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>invalidEmailCharacter</constant-name>
<constant-value><![CDATA[$%'*+:;<=>?^_`{|}]]></constant-value>
</constant>
<constant>
<constant-name>validCharacterReguler</constant-name>
<constant-value><![CDATA[^[^${invalidCharacter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>validEmail</constant-name>
<constant-value><![CDATA[^[^${invalidEmailCharacter}]*$]]></constant-value>
</constant>
<constant>
<constant-name>defaultDateFormat</constant-name>
<constant-value><![CDATA[MM/dd/yyyy]]></constant-value>
</constant>
<constant>
<constant-name>invalidCharacterForFilter</constant-name>
<constant-value><![CDATA[$%'*:'<=>^`{|}]]></constant-value>
</constant>
<constant>
<constant-name>validCharacterRegulerForFilter</constant-name>
<constant-value><![CDATA[^[^${invalidCharacterForFilter}]*$]]></constant-value>
</constant>
</global>
<formset>
<form name="book">
<field property="id" depends="maxlength,required">
<arg0 key="book.id.displayName" />
<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
</field>
<field property="name" depends="maxlength,required">
<arg0 key="book.name.displayName" />
<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
</field>
<field property="author" depends="maxlength">
<arg0 key="book.author.displayName" />
<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
<var>
<var-name>maxlength</var-name>
<var-value>5</var-value>
</var>
</field>
<field property="price" depends="mask">
<arg0 key="book.price.displayName" />
<arg1 name="number" key="${var:mask}" resource="false" />
<var>
<var-name>mask</var-name>
<var-value>^[0-9]</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
9 写jsp页面也就是刚才在controller中配置的formView。注意用<spring:bind path="book.xxx">绑订字段。用value="<core:out value="${book.id}"/>"输出上次输入的值。在该页引入messages.jsp用于显示出错消息。
<!--addbook.jsp-->
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="WEB-INF/tld/spring-form.tld" prefix="form"%>
<%@ taglib uri="WEB-INF/tld/c-rt.tld" prefix="core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<script type="text/javascript" src=""></script>
<style type="text/css">
</style>
</head>
<body>
<%@ include file="messages.jsp" %>
<form method="post" action="addbook.do">
<spring:bind path="book.id">
<input type="text" name="id" value="<core:out value="${book.id}"/>"/>
</spring:bind>
<spring:bind path="book.name">
<input type="text" name="name" value="<core:out value="${book.name}"/>"/>
</spring:bind>
<spring:bind path="book.author">
<input type="text" name="author" value="<core:out value="${book.author}"/>"/>
</spring:bind>
<spring:bind path="book.price">
<input type="text" name="price" value="<core:out value="${book.price}"/>"/>
</spring:bind>
<input type="submit" value="Google" /><br>
</form>
</body>
</html>
10 写messages.jsp 注意image路径。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="WEB-INF/tld/c-rt.tld" prefix="core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<SCRIPT LANGUAGE=javascript>
function hideMessage() {
if ( messageTR.style.display == "") {
messageTR.style.display = "none";
}
}
</SCRIPT>
<spring:bind path="book.*">
<core:if test="${not empty status.errorMessages}">
<%
if(request.getAttribute("errors") == null){
List errors = new ArrayList();
request.setAttribute("errors",errors);
}
%>
<core:forEach var="error" items="${status.errorMessages}">
<%List errors = ((List)request.getAttribute("errors"));
errors.add(pageContext.getAttribute("error"));
%>
</core:forEach>
</core:if>
</spring:bind>
<core:if test="${not empty errors or not empty messages}">
<table border=0 cellpadding=0 cellspacing=0 width="95%" align="center">
<tr id='messageTR' style="DISPLAY:">
<td align="center">
<core:if test="${not empty errors}">
<core:set var="hasMessage" value="true"/>
<div align="left" class="error fade-ffff00" id="error">
<core:forEach var="error" items="${errors}">
<img src="<%=request.getContextPath()%>/images/iconWarning.gif" alt='Warning' class="icon" />
<core:out value="${error}" escapeXml="false"/><br/>
</core:forEach>
</div>
<core:remove var="errors"/>
</core:if>
<core:if test="${not empty messages}">
<core:set var="hasMessage" value="true"/>
<div align="left" class="message fade-ffff00" id="message">
<core:forEach var="msg" items="${messages}">
<img src="<%=request.getContextPath()%>/images/iconInformation.gif" alt='Information' class="icon" />
<core:out value="${msg}" escapeXml="false"/><br/>
</core:forEach>
</div>
<core:remove var="messages"/>
</core:if>
<core:if test="${hasMessage eq 'true'}"><a href="javascript:hideMessage();"> <spring:message code="common.messages.close"/> </a></core:if>
</td>
</tr>
</table>
</core:if>
相关推荐
这个validate验证框架中的actiionerror级别的错误的验证提示,并包含了如何在一个Action中处理多个业务逻辑,(struts1.x 中的DispatcheAction),例子比较简单,希望对大家学习struts有所帮助。
在IT领域,特别是Web开发中,...通过以上步骤,我们可以利用Struts2和jQuery.validate框架构建一个健壮的用户名唯一性检查系统,确保数据的完整性和系统的安全性。这不仅提高了用户体验,还加强了数据管理的严谨性。
非常好的Jquery validate:每个案例独立,都有注释 讲解了: 环境搭建 常见验证方法配置 国际化错误消息 自定义方法和远程验证 给验证添加 图标效果
本篇文章将深入探讨Apache Commons Validator框架,并通过一个简单的小例子来演示其使用方法。 Apache Commons Validator框架提供了对各种数据类型的验证规则,如字符串长度、数字范围、日期格式等。它支持自定义...
jQuery Validate 是一个强大的客户端表单验证插件,用于在用户提交数据之前检查其有效性。它提供了丰富的验证规则和自定义选项,确保用户输入的数据符合预设的要求。在本文中,我们将深入探讨 `jQuery Validate` ...
3. **编写Action类**:创建一个Action类,继承自Struts2提供的基类,并实现validate方法。在这个方法中,我们可以定义各种验证规则,比如非空检查、长度限制、格式验证等。如果验证失败,Struts2会自动将错误消息...
包含 1、talent-validate2.1 前台js 验证框架 2、修改 talent局部样式,做了几个例子
Struts框架是一个经典的Java Web开发框架,由Apache软件基金会维护,它主要负责处理MVC(Model-View-Controller)架构中的Controller部分。在Struts框架中,`validate`功能是用于进行表单验证的重要机制,它帮助...
以下是一个简单的例子,展示如何在实体类中使用Hibernate Validator定义验证规则: ```java import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; public class User { @Not...
自定义`validate`验证是Struts1框架的一个关键特性,允许开发者根据业务需求定制特定的验证规则。通常,这个过程包括以下几个步骤: 1. **创建Validator ActionForm**:在Struts1中,表单数据通常是通过ActionForm...
SSM 是一个常见的Java Web开发框架组合,由Spring MVC、MyBatis和Maven三个核心组件构成。这个项目提供了一个完整的开发环境,适用于快速构建基于Web的应用程序。 **Spring MVC** 是Spring框架的一部分,用于处理...
`validatelogin6`可能是这个例子中的一个关键文件,可能包含了一个实现了`validate`机制的登录表单验证实例。具体的内容可能包括了`LoginForm`的实现、`struts-config.xml`的配置以及相关的JSP页面,用于展示验证...
本篇将通过一个实际的小例子,深入剖析Thinkphp5的核心概念和常用功能,帮助你更好地理解和应用这个框架。 首先,我们要明白Thinkphp5的基本架构。它采用了MVC(Model-View-Controller)设计模式,将业务逻辑、数据...
压缩包内的"页面校验非常好的例子"文件,很可能是包含了一个或多个示例,展示如何在实际项目中应用`validate.js`进行表单验证。这些示例通常会包括HTML结构、JavaScript代码以及可能的CSS样式,帮助开发者快速理解和...
`jQuery Validate`是一个基于JavaScript库`jQuery`的验证插件,用于高效地验证用户在表单中输入的数据。它提供了一系列预定义的验证规则,同时允许开发者自定义验证方法以满足特定需求。该框架对于创建具有国际化...
在这个例子中,我们创建了一个表单并定义了两个验证规则:邮箱必须存在且为有效格式,密码必须存在且长度至少为6位。当用户尝试提交表单时,如果输入不符合规则,`jQuery Validate` 会阻止表单提交并显示相应的错误...
Bootstrap Validate 是一个强大的JavaScript库,专门用于实现网页表单的验证功能。这个库基于流行的前端框架Bootstrap,提供了优雅且可扩展的方式来确保用户在提交表单时输入的数据是完整且有效的。Bootstrap ...
Struts1是一个经典的Java Web开发框架,用于构建MVC(模型-视图-控制器)架构的应用程序。在Struts1中,验证框架是处理用户输入数据校验的重要组成部分,它帮助开发者确保用户提交的数据符合预定义的规则,从而提高...
这个"java做的struts验证框架例子"是为了展示如何在Struts中实现数据验证。在Java Web开发中,数据验证通常分为客户端验证和服务器端验证两部分。客户端验证可以在用户提交表单前通过JavaScript进行,而服务器端验证...
【最新实用的Validate通用表单验证Jquery插件】是一个高效、灵活的前端验证工具,专为使用Jquery框架的Web开发人员设计。这个插件极大地简化了表单验证的过程,使得用户输入的数据在提交前就能得到有效的检查,从而...