与其各自字段对应的验证分隔

时间:2014-05-28 09:41:26

标签: java javascript php

<script>
function trim(str){
     var str=str.replace(/^\s+|\s+$/,'');
     return str;
}
function validReg(){
      var password1=$('#password1').val();
      var email1=$('#email1').val();
      var mobile1=$('#mobile1').val();
      var dataString = '&password1='+ password1 + '&email1='+ email1 + '&mobile1='+ mobile1;
      $("#flash").show();
      $("#flash").fadeIn(400).html('<img src="image/loading.gif" />');
      $.ajax({
      type: "POST",
      url: "@cus/au_register.php",
      data: dataString,
      cache: false,
      success: function(result){
               var result=trim(result);
               $("#flash").hide();
               if(result=='correct'){
                     window.location='index.php';
               }else{
                     $("#errorMessage").html(result);
               }
      }
      });
}
</script>

form:
-----

       <div id="errorMessage" style="color:RED;"></div>
 <p><span class="register-numbering-text">New user? Create account</span></p>
        <li>
          <label> <span>Mobile No.*</span>
            <input type="mobile" id="mobile1" name="cst_mob" class="frm_mst" size="40" tabindex="1" placeholder="Please enter your mobile no.">
          </label>
        </li>
        <li>
          <label> <span>Email*</span>
            <input type="email" name="cst_email" id="email1" class="frm_mst" size="40" tabindex="2" placeholder="Please enter a valid email address">
          </label>
        </li>
        <li>
          <label> <span>Password*</span>
            <input type="password" name="cst_pwd" id="password1" class="frm_mst" size="20" tabindex="3" placeholder="Please enter your password" >
          </label>
        </li>
        <li>
        <p><span style="font-size:14px; font-weight:normal;">By clicking Create Account, you agree to our 
<a href="">Terms & Conditions</a> and that you have read our <a href="">Privacy Policy</a></span></p>
        </li>
        <li>
          <button name="submit" tabindex="11" type="submit" id="create-account-submit" onclick="validReg()">Create Account</button>
        </li>
      </form>

au-register.php
session_start();
include_once("../de@ler/sk-incd/sk-cond.php");
$i=$_SERVER['REMOTE_ADDR'];
$date=date("y-m-d");
$message=array();
$query1=mysql_query("select * from tb_cst_lgns where cst_cnt='$_POST[mobile1]'");
if(isset($_POST['email1']) && !empty($_POST['email1'])){
    $email1=mysql_real_escape_string($_POST['email1']);
    if(!filter_var($_POST['email1'], FILTER_VALIDATE_EMAIL))
    {
    $message[]='not valid email address';
    }
}else{
    $message[]='Please enter email';
}
if(isset($_POST['password1']) && !empty($_POST['password1'])){
    $password1=mysql_real_escape_string($_POST['password1']);
}else{
    $message[]='Please enter password';
}
if(isset($_POST['mobile1']) && !empty($_POST['mobile1'])){
    $mobile1=mysql_real_escape_string($_POST['mobile1']);
    if(!preg_match('/^\d{10}$/',$_POST['mobile1']))
    {
    $message[]='not a valid number';
    }
}else{
    $message[]='Please enter mobile';
}

$countError=count($message);

if($countError > 0){
     for($i=0;$i<$countError;$i++){
            echo ucwords($message[$i])." , "; 
     }

if(mysql_num_rows($query1)>0)
{
         echo 'Phone number already registered';
}
}
else{
    $query="select * from tb_cst_lgns where cst_email='$email1'";

    $res=mysql_query($query);
    $checkUser=mysql_num_rows($res);
    if($checkUser > 0){
        // $_SESSION['LOGIN_STATUS']=true;
         //$_SESSION['UNAME']=$uname;
         echo 'Email id is already exist';
    }else{
         mysql_query("insert into tb_cst_lgns values('','','','$email1','$password1','$mobile1','','','','','','','$i','$date','1')");
         $_SESSION[au_user_session]=$email1;
         echo "correct";
             }
}

现在我的验证显示在寄存器区域上方的一行中。但我希望每个验证都应显示在其各自的字段旁边。如何将验证分开并将它们对应于各自的字段。

0 个答案:

没有答案