jquery validate
jQuery Validate 插件为表单提供了强大的验证功能,不用自己去写各种验证。默认提示是英文,可以选择其他语言。
简单使用
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="jquery-validation-1.14.0/lib/jquery.js"></script> <script type="text/javascript" src="jquery-validation-1.14.0/dist/jquery.validate.min.js"></script> <script type="text/javascript" src="jquery-validation-1.14.0/dist/localization/messages_zh.js"></script> <script type="text/javascript"> $(function(){ $("#myform").validate( { /* 重写错误显示消息方法,以alert方式弹出错误消息 */ showErrors: function(errorMap, errorList) { var msg = ""; $.each( errorList, function(i,v){ msg += (v.message+"\r\n"); }); if(msg!="") alert(msg); }, } ); }) </script> </head> <body> <form id="myform" action=""> <input type="text" minlength="5" required=true number=true> <input type="submit"> </form> </body> </html>
上面重写了信息的提示方式,改为以弹出框的形式提示信息。
详细的使用看这 http://www.runoob.com/jquery/jquery-plugin-validate.html