第一步:
$('#form_store_info').validate({ errorPlacement: function(error, element){ element.nextAll('span').first().after(error); }, rules : { seller_name: { required: true, maxlength: 50, seller_name_exist: true, seller_name_illegal: true },第二步:
jQuery.validator.addMethod("seller_name_exist", function(value, element, params) { var result = true; $.ajax({ type:"GET", url:'<?php echo urlShop('store_joinin', 'check_seller_name_exist');?>', async:false, data:{seller_name: $('#seller_name').val()}, success: function(data){ if(data == 'true') { $.validator.messages.seller_name_exist = "<?php echo $lang['store_joinin_c2c_apply_step3_seller_account_has_been_existence']?>"; result = false; } } }); return result; }, ''); jQuery.validator.addMethod("seller_name_illegal",function(value, element, params){ var result = true; $.ajax({ type:"get", url:'<?php echo urlShop('store_joinin','check_seller_name_illegal')?>', async:false, data:{seller_name: $('#seller_name').val()}, success:function(data){ if(data == 'true'){ $.validator.messages.seller_name_illegal = "<?php echo '该商家账号系统禁用'?>"; result = false; } } }); return result; },'')第三步:PHP
public function check_seller_name_existOp() { $condition = array(); $condition['seller_name'] = $_GET['seller_name']; $model_seller = Model('seller'); $result = $model_seller->isSellerExist($condition); if($result) { echo 'true'; } else { echo 'false'; } } public function check_seller_name_illegalOp(){ $model_black_list = Model('black_list'); $r = $model_black_list->getKeywordList(); $black_list = array(); foreach($r as $k=>$v){ $black_list[] = $v['keyword']; } $result = in_array($_GET['seller_name'],$black_list); if($result) { echo 'true'; } else { echo 'false'; } }