jquery验证插件jquery.validationEngine.js ①:引⼊js类库以及样式
<link href="${basePath}/css/validationEngine.jquery.css"
rel="stylesheet" type="text/css" />
<script language="javascript"
src="${basePath}/js/jquery/jquery-1.6.min.js"></script>
<script src="${basePath}/js/jquery/jquery.validationEngine-zh_CN.js"
type="text/javascript" charset="utf-8"></script>
<script src="${basePath}/js/jquery/jquery.validationEngine.js"
type="text/javascript" charset="utf-8"></script>
②:为表单添加验证的样式(通过注册表单说明下有哪些验证)
<form action="${basePath}/customer/customer_save.action" id="signup_form"
method="post">
<table border="0" cellspacing="0" cellpadding="0"
class="table_2">
<tr>
<th valign="top">
<span class="must">*</span>⽤户名:
</th>
<td>
<input
class="validate[required,minSize[6],custom[onlyLetterNumber],maxSize[20],ajax[ajaxUserName]] input_1"
id="user_userNo" name="customer.username" type="text" />
<p>
6-20个字符,允许英⽂字母、数字、下划线.
</p>
</td>
</tr>
<tr>
<th valign="top">
<span class="must">*</span>密码:
</th>
<td>
<input
class="validate[required,minSize[6],custom[onlyLetterNumber],maxSize[20]] input_1"
id="user_passwd" name="customer.password" maxLength="20"
type="password" />
<p>
请选⽤安全的密码
</p>
</td>
</tr>
<tr>
<th>
<span class="must">*</span>确认密码:
</th>
<td>
<input class="validate[required,equals[user_passwd]] input_1"
id="user_password_confirmation" maxLength="20"
name="repassword" size="30" type="password" />
</td>
</tr>
<tr>
<th valign="top">
<span class="must">*</span>电⼦邮箱:
</th>
class="validate[required,custom[email]] input_1"
id="user_email" name="email" maxLength="100"
type="text" />
</td>
</tr>json自动格式化的软件
<tr>
<th valign="top">
住址:
</th>
<td>
<input
class="input_1"
id="user_userName" maxlength="100" name="customer.address"
type="text" />
</td>
</tr>
<tr>
<th valign="top">
⼿机:
</th>
<td>
<input
class=" input_1"
id="user_mobile" maxlength="11" name="bile"
type="text" />
</td>
</tr>
<tr>
<th>
<span class="must">*</span>验证码:
</th>
<td>
<input
class="validate[required,ajax[ajaxVerifyCode]] input_3"表白网站源码网页制作
id="verifyCode" name="verifyCode" type="text" maxLength="4" />
<img src="${basePath}/system/validate.action" id="verify" alt="验证码"
title="看不清?点击换另⼀张" οnclick="RefreshCode(this)" width="90px" height="30px"> <a href="javascript:void(0);"
οnclick="ElementById('verify'))">看不清。换⼀个</a>
<script language="javascript">
function RefreshCode(obj){
obj.src =obj.src+"?code=" + Math.random();
}
</script>
</td>
</tr>
<tr>
<th>
</th>
<td>
<input name="checkbox" type="checkbox"
class="validate[required]" id="auto" checked="checked" />
<label for="auto">
我已经阅读并同意
</label>
<a href="agree.jsp" target="_blank">注册条款</a>
</td>
</tr>
</table>
<div class="btn_area_1" >
<input type="submit" name="button" id="button" value="注 册"
class="btn_1" />
说明:⽤ 户 名————验证⾮空,长度在6到20之间,通过ajaxUserName验证⽤户名唯⼀ 密 码————验证⾮空,长度在6到20之间
确认密码————验证⾮空,必须和密码填写内容⼀致
邮 箱————⾮空且为正确的邮箱格式
使用php软件的视频验 证 码————⾮空,ajax验证验证码是否正确
注册条款————⾮空
这⾥附上juery.validationgEngine-zh_CN.js代码
(function($){
$.fn.validationEngineLanguage = function(){
};
$.validationEngineLanguage = {
newLang: function(){
$.validationEngineLanguage.allRules = {
"required": { // Add your regex rules here, you can take telephone as an example
"regex": "none",
"alertText": "* 此处不可空⽩",
"alertTextCheckboxMultiple": "* 请选择⼀个项⽬",
"alertTextCheckboxe": "* 您必须勾选此栏",
"alertTextDateRange": "* ⽇期范围不可空⽩"
},
"requiredInFunction": {
"func": function(field, rules, i, options){
return (field.val() == "test") ? true : false;
},
"alertText": "* Field must equal test"
},
"dateRange": {jquery下载文件插件
"regex": "none",
list contain"alertText": "* ⽆效的 ",
"alertText2": " ⽇期范围"
},
"dateTimeRange": {
"regex": "none",
"alertText": "* ⽆效的 ",
"alertText2": " 时间范围"
},
"minSize": {
"regex": "none",
"alertText": "* 最少 ",
"alertText2": " 个字符"
},
"maxSize": {
"regex": "none",
"alertText": "* 最多 ",
"alertText2": " 个字符"
},
"groupRequired": {
"regex": "none",
"alertText": "* 你必需选填其中⼀个栏位"
},
"min": {
"regex": "none",
"alertText": "* 最⼩值為 "
},
"regex": "none",
"alertText": "* 最⼤值为 "
},
"past": {
"regex": "none",
"alertText": "* ⽇期必需早于 "
},
span靠右显示
"future": {
"regex": "none",
"alertText": "* ⽇期必需晚于 "
},
"maxCheckbox": {
"regex": "none",
"alertText": "* 最多选取 ",
"alertText2": " 个项⽬"
},
"minCheckbox": {
"regex": "none",
"alertText": "* 请选择 ",
"alertText2": " 个项⽬"
},
"equals": {
"regex": "none",
"alertText": "* 请输⼊与上⾯相同的密码"
},
"creditCard": {
"regex": "none",
"alertText": "* ⽆效的信⽤卡号码"
},
"phone": {
// credit: jquery.h5validate.js / orefalo
"regex": /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
"alertText": "* ⽆效的电话号码"
},
"mobile":{
"regex":/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/,
"alertText":"* ⽆效⼿机号"
},
"email": {
// Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin projects.scottsplayground/email_address_validation/
"regex": /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)(((( //regex":/^[a-zA-Z0-9_.]{1,}@[a-zA-Z0-9_]{1,}.[a-zA-Z0-9_]{1,}|.[a-zA-z0-9_]{1,}$/,
"alertText": "* 邮件地址需由字母、数字或下划线组成"
},
"integer": {
"regex": /^[\-\+]?\d+$/,
"alertText": "* 不是有效的整数"
},
"number": {
// Number, including positive, negative, and floating decimal. credit: orefalo
"regex": /^[\-\+]?((([0-9]{1,3})([,][0-9]{3})*)|([0-9]+))?([\.]([0-9]+))?$/,
"alertText": "* ⽆效的数字"
},
"post":{
"regex":/^[1-9][0-9]{5}$/,
"alertText":"* ⽆效,6位数字,不能以0开头"
},
"date": {
"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/,
"alertText": "* ⽆效的⽇期,格式必需为 YYYY-MM-DD"
},
"ipv4": {
"regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,
"alertText": "* ⽆效的 IP 地址"
"url": {
"regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0- "alertText": "* Invalid URL"
},
"onlyNumberSp": {
"regex": /^[0-9\ ]+$/,
"alertText": "* 只能填数字"
},
"onlyLetterSp": {
"regex": /^[a-zA-Z\ \']+$/,
"alertText": "* 只接受英⽂字母⼤⼩写"
},
"onlyLetterNumber": {
"regex": /^[0-9a-zA-Z_]+$/,
"alertText": "* 允许英⽂字母、数字、下划线"
},
// --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings
"ajaxUserCall": {
"url": "ajaxValidateFieldUser",
// you may want to pass extra data on the ajax call
"extraData": "name=eric",
"alertText": "* 此名称已被其他⼈使⽤",
"alertTextLoad": "* 正在确认名称是否有其他⼈使⽤,请稍等。"
},
"ajaxUserCallPhp": {
"url": "phpajax/ajaxValidateFieldUser.php",
// you may want to pass extra data on the ajax call
"extraData": "name=eric",
// if you provide an "alertTextOk", it will show as a green prompt when the field validates
"alertTextOk": "* 此帐号名称可以使⽤",
"alertText": "* 此名称已被其他⼈使⽤",
"alertTextLoad": "* 正在确认帐号名称是否有其他⼈使⽤,请稍等。"
},
"ajaxNameCall": {
// remote json service location
"url": "ajaxValidateFieldName",
// error
"alertText": "* 此名称可以使⽤",
// if you provide an "alertTextOk", it will show as a green prompt when the field validates
"alertTextOk": "* 此名称已被其他⼈使⽤",
// speaks by itself
"alertTextLoad": "* 正在确认名称是否有其他⼈使⽤,请稍等。"
},
"ajaxNameCallPhp": {
// remote json service location
"url": "phpajax/ajaxValidateFieldName.php",
// error
"alertText": "* 此名称已被其他⼈使⽤",
// speaks by itself
"alertTextLoad": "* 正在确认名称是否有其他⼈使⽤,请稍等。"
},
"validate2fields": {
"alertText": "* 请输⼊ HELLO"
},
/
/tls warning:homegrown not fielded
"dateFormat":{
"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\ "alertText": "* ⽆效的⽇期格式"
},
//tls warning:homegrown not fielded
"dateTimeFormat": {
"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$ "alertText": "* ⽆效的⽇期或时间格式",
"alertText2": "可接受的格式: ",
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论