Discuss / JavaScript / 表示<p id="test-error"></p>一定有用

表示<p id="test-error"></p>一定有用

Topic source

解集SS

#1 Created at ... [Delete] [Delete and Lock User]
'use strict';
var checkRegisterForm = function () {
    var u = $("#username").val(),
        p = $("#password").val(),
        r = $("#password-2").val();

    var whatError = function () {
        var str = "注册失败。";
        if(!/^\w{3,10}$/.test(u)) {
            str = "用户名必须是3-10位英文字母或数字。";
        } else if(p.length < 6 || p.length > 20) {
            str = "口令长度必须在6-20位之间。";
        } else if(p !== r) {
            str = "两次输入口令必须一致。";
        }
        return str;
    };

    if(p !== r || !/^\w{3,10}$/.test(u) || p.length < 6 || p.length > 20) {
        $("#test-error").text("出错啦!" + whatError());
        return false;
    }
    return true;
};

  • 1

Reply