[ 转 ] http://www.cnlvzi.com/index.php/Index/article/id/58

最近做验证功能时,用到jquery.validate.js中的remote远程验证方式。
网上查了一下,关于这个remote的资料少之好少,看了一个API介绍,介绍也相当少。
无奈下,只能看了下,jquery.validate.js源码,最终是搞明白了。
以下写下来,方便以后的人,使用。

注意如下内容:

1,远程返回数据时,一定要返回"true"或者"false",否则就是永远就是验证不通过。

2,remote有两种方式,如下就介绍remote与PHP间的验证
(1)meta String方式(当然这种方式要引入jquery.metadata.js)
以下是我的HTML代码

<input type="text" name="moblie" id="jform_moblie" value=""

 class="input {validate:{required:true,telphoneValid:  true,remote:'moblie_register.php?fun=moblie', messages:{required:'请填写手机号码!', telphoneValid:'请输入正确的手机号',remote:'该手机号码已被注册! <a href=login.php target=_blank>登录?</a>'}}}" />

直接remote提交到PHP页面中去。默认提交类型是GET方式提交
PHP代码:

if ($_GET['fun']=='moblie') {//检查手机是否已注册
$moblie_number=trim($_GET['moblie']);
$exists_moblie=$db->query_first("select acc_moblie_number from t_account where
acc_moblie_number='".$moblie_number."'");
if (empty($exists_moblie['acc_moblie_number'])) {
$return['type']='true';
$return['info']='此手机号码可注册!';
}else{
$return['type']='false';
$return['info']='该手机号码已被注册!';
}
exit($return['type']);
}
这样就完成的验证

(2)rules方式

$("#Form2").validate({
rules: { //定义验证规则,其中属性名为表单的name属性
"mail_account": {
required: true,
email: true ,
remote: {
url: '<--?php echo $this--->base;?-->/maileckmail',
type: 'POST',
dateType: 'json',
data: { mail_account:function(){
return $('#mail_account').val();
}
}
} },
},
messages: {
"mail_account": {
email: "请输入正确的邮箱地址(例如 myemail@qq.com)",
remote: "该邮箱已存在!"
},
}
});

PHP代码:

function checkMail(){
$mail_account = $_POST['mail_account'];
if($this->Mail->findByMailAccount($mail_account))
echo 'false';
else
echo 'true';
die();
}

PHP + jquery.validate remote的用法的更多相关文章

  1. jquery.validate remote的用法

    1,远程返回数据时,一定要返回"true"或者"false",否则就是永远就是验证不通过. 2,remote有两种方式,如下就介绍remote与PHP间的验证( ...

  2. jquery.validate.min.js 用法方法示例

    页面html 代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  3. jquery.validate remote 和 自定义验证方法

    jquery.validate remote 和 自定义验证方法 $(function(){ var validator = $("#enterRegForm").validate ...

  4. jquery validate remote验证唯一性

    jquery.validate.js 的 remote 后台验证 之前已经有一篇关于jquery.validate.js验证的文章,还不太理解的可以先看看:jQuery Validate 表单验证(这 ...

  5. jquery.validate.js表单验证 jquery.validate.js的用法

    jquery.validate.js这个插件已经用了2年多了,是一个不可多得的表单验证最方便快捷的插件.基于jquery的小插件,基本小白一学就会上手,对于项目表单页面比较多,元素比较多的校验,该插件 ...

  6. 关于jquery.validate.js的用法

    // 手机号码验证 jQuery.validator.addMethod("isMobile", function(value, element) {   var length = ...

  7. jQuery Validate 插件验证,,返回不同信息(json remote)自定义

    问题 申请账号需要确认该账号是存在 jquery.validate.js中的remote Jquery Ajax获取后台返回的Json数据后,添加自定义校验 解题思路:输入的登陆信息远程验证是否该账号 ...

  8. ASP.NET MVC Jquery Validate 表单验证的多种方式

    在我们日常开发过程中,前端的表单验证很重要,如果这块处理不当,会出现很多bug .但是如果处理的好,不仅bug会很少,用户体验也会得到很大的提升.在开发过程中我们可以不借助 JS 库,自己去手写 JS ...

  9. [转]ASP.NET MVC Jquery Validate 表单验证的多种方式介绍

    在我们日常开发过程中,前端的表单验证很重要,如果这块处理不当,会出现很多bug .但是如果处理的好,不仅bug会很少,用户体验也会得到很大的提升.在开发过程中我们可以不借助 JS 库,自己去手写 JS ...

随机推荐

  1. sql select(A.B)拼接

    需要做的工作:把DBtable里边的某两个字段,(当然可以更多)或者不同表,道理类似,用某个符号拼接起来. 比如(Table.A).(Tables.B) oracle里边可以这样写,sql没试: se ...

  2. 关于使用openfiler作为共享存储来安装rac时的问题

    关于使用openfiler作为共享存储来安装rac时的问题 第一:一定要使用openfiler-2.3-x86-disc1.iso这个版本号的openfiler,不要使用其它版本号的openfiler ...

  3. iOS xmpp协议实现聊天之openfire的服务端配置(一)

    今天弄这个openfire服务端的配置直接苦了一逼,只是好在最后最终配置好了.首先感谢@月光的尽头的博客给了我莫大的帮助. 切入正题,首先说一下iOS xmpp协议实现聊天openfireserver ...

  4. 【Web前端】清除浮动&amp;css中文字体

    清理浮动有非常多种方式,像使用 br 标签自带的 clear 属,使用元素的 overflow.使用空标签来设置 clear:both 等等.但考虑到兼容问题和语义化的问题,一般我们都会使用例如以下代 ...

  5. java验证码图片

    package com.su.servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; impor ...

  6. 获取IOS应用安装列表

    原文转载至 http://blog.csdn.net/justinjing0612/article/details/8887747 转自鸟哥博客:http://blog.cnrainbird.com/ ...

  7. Kubernetes实战阅读笔记--1、介绍

    1.业界根据云计算提供服务资源的类型将其划分为三大类: 基础设施即服务(Infrastructure-as-a-Service,IaaS).平台即服务(Platform-as-a-Service,Pa ...

  8. yum 安装 mysql

    安装 yum -y install mysql-server 开机自启动 chkconfig mysqld on 设置账户密码 启动 service mysqld start -- 进入mysql库 ...

  9. Statelessness Provide credentials with the request. Each request MUST stand alone and should not be affected from previous conversation happened from same client in past.

    The server never relies on information from previous requests. Statelessness As per the REST (REpres ...

  10. ES6 数组的解构赋值

    数组的解构赋值 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1; let b = ...