English 中文(简体)
Jquery 核对密码与php + Json
原标题:Jquery checking that passwords match with php + Json

我的表格是我与联合材料和共同财产计划一起验证的。 在我试图检查密码是否吻合时,所有东西都相距甚远。

形式如下:

<div>
                    <label for="passlength">Password, valid: 0-9</label>
                    <input type="text" name="passlength" value="<?=@$_REQUEST[ passlength ]?>" id="passlength" />
                    <span id="validatePasslength"><?php if ($error) { echo $error[ msg ]; } ?></span>
                </div>
                <div>
                    <label for="passlength">Password2, valid: 0-9</label>
                    <input type="text" name="passlength2" value="<?=@$_REQUEST[ passlength2 ]?>" id="passlength2" />
                    <span id="validatePasslength2"><?php if ($error) { echo $error[ msg ]; } ?></span>
                </div>

这就是 Java:

    var r = $( #passlength ).val()
;
        var validatePasslength2 = $( #validatePasslength2 );
        $( #passlength2 ).keyup(function () {

            var t = this;
            if (this.value != this.lastValue) {
                if (this.timer) clearTimeout(this.timer);
                validatePasslength2.removeClass( error ).html( <img src="../../images/layout/busy.gif" height="16" width="16" /> checking availability... );

                this.timer = setTimeout(function () {
                    $.ajax({
                        url:  ajax-validation.php ,
                        data:  action=check_passlength2&passlength=  + r +  &passlength2=  + t.value,
                        dataType:  json ,
                        type:  post ,
                        success: function (j) {
                            validatePasslength2.html(j.msg);
                        }
                    });
                }, 200);
                this.lastValue = this.value;
            }
        });

这里是:

//Check for passlength
        if (@$_REQUEST[ action ] ==  check_passlength  && isset($_SERVER[ HTTP_X_REQUESTED_WITH ])) {
        // means it was requested via Ajax
        echo json_encode(check_passlength($_REQUEST[ passlength ]));
        exit; // only print out the json version of the response
    }

    function check_passlength($password) {
//        global $taken_usernames, $usersql;
        $resp = array();
//        $password = trim($password);
      if (!preg_match( /^[0-9]{1,30}$/ , $password)) {
        $resp = array("ok" => false, "msg" => "0-9 Only");
    } else if (preg_match( /^[0-9]{1,2}$/ , $password)) {
                        $resp = array("ok" => false, "msg" => "Password too short");
        } else if (preg_match( /^[0-9]{6,30}$/ , $password)) {
                                $resp = array("ok" => false, "msg" => "Password too long");
    } else {
        $resp = array("ok" => true, "msg" => "Password ok");
    } 

        return $resp;
    }


//Check for passlength2
        if (@$_REQUEST[ action ] ==  check_passlength2  && isset($_SERVER[ HTTP_X_REQUESTED_WITH ])) {
        // means it was requested via Ajax
        echo json_encode(check_passlength2($_REQUEST[ passlength ],$_REQUEST[ passlength2 ]));
        exit; // only print out the json version of the response
    }

    function check_passlength2($password,$password2) {
//        global $taken_usernames, $usersql;
        $resp = array();
//        $password = trim($password);
      if (!preg_match( /^[0-9]{1,30}$/ , $password2)) {
                $resp = array("ok" => false, "msg" => "0-9 Only");
        } else if (preg_match( /^[0-9]{1,2}$/ , $password2)) {
                                $resp = array("ok" => false, "msg" => "Password too short");
        } else if (preg_match( /^[0-9]{6,30}$/ , $password2)) {
                                $resp = array("ok" => false, "msg" => "Password too long");
        } else if ($password !== $password2) {
                                $resp = array("ok" => false, "msg" => "Passwords do not match");
        } else {
                $resp = array("ok" => true, "msg" => "Password ok");
        }

        return $resp;
    }

I, pretty, is a issue with the j>, if I set : > >, 1234; It. ?

问题回答

你们只想看到这些口号是否与时俱进? 是否有高技能? 我失踪了吗?

您可以单单单单单单单使用小 j来检查第一密码的长度,然后在第二场模糊的情况下检查实地1=实地2。

我注意到的一点是,第二个领域的标签有错的“因”归属。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签