Home Web Front-end JS Tutorial Share jquery plug-in--form validation

Share jquery plug-in--form validation

Jun 19, 2017 am 10:50 AM
jquery share plug-in form verify

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

var regAction = (function () {

    var defaultOpts = {

        'regform' 'regfrom',

        'username' 'username',

        'userpwd' 'userpwd',

        'confirmpwd' 'confirmpwd',

        'checkcode' 'checkcode',

        'accept' 'accept',

        'errorTrips' 'errorTrips',

        'channel' 'channel',

        'loginAuto' 'loginAuto',

        'btnAction' 'btnAction'

 

    },

    isreg = 1;

    //去掉空格

    function trim(str) {

        return str.replace(//s+$|^/s+/g, '');

    }

 

    //检测email

    function isEmail(email) {

        return /^[/w/-/.]+@[/w/-/.]+(/./w+)+$/i.test(email)

    }

 

    //检测用户名

    function checkUserName(callback) {

        var optsObj = defaultOpts;

        var nameObj = optsObj.username;

        var errorTripsObj = optsObj.errorTrips;

        var value = trim(nameObj.val());

        nameObj.val(value);

 

        if (!isEmail(value)) {

            errorTripsObj.html('请输入正确的邮箱地址').css('visibility''visible');

            nameObj.focus();

            if (callback) {

                callback(false);

            }

        else {

            $.ajax({

                url : '/index.php?ac=account&op=checkuser',

                dataType : 'json',

                type : 'post',

                data : {

                    username : value

                },

                success : function (res) {

                    if (res) {

                        switch (res.string) {

                        case '1':

                            //errorTripsObj.html('该邮箱已经被注册').css('visibility', 'visible');

                            optsObj.checkcode.hide();

                            $("#jChkcode").hide();

                            $("#jPrivacy").hide();

                            $("#jRemeberBox").show();

                            $("#repwd-box").hide();

                            $("#jhd").text("登录快盘");

                            $("#jcnt").text("随时随地查看文件");

                            optsObj.btnAction.val("立即登录");

                            isreg = 2;

                            //nameObj.focus();

                            if (callback) {

                                //callback(false);

                                callback(true);

                            }

                            nameObj.change(function () {

                                optsObj.checkcode.show();

                                $("#jChkcode").show();

                                $("#jPrivacy").show();

                                $("#jRemeberBox").hide();

                                $("#repwd-box").show();

                                $("#jhd").text("注册快盘");

                                $("#jcnt").text("只需5秒,立即拥有15GB空间");

                                optsObj.btnAction.val("立即注册");

                                isreg = 1;

                            });

                            break;

                        case '2':

                        default:

                            errorTripsObj.css('visibility''hidden');

                            if (callback) {

                                callback(true);

                            }

                        }

                    else {

                        if (callback) {

                            callback(true);

                        }

                    }

                }

            })

        }

 

    }

    //检测密码

    function checkPwd(callback) {

        var optsObj = defaultOpts;

        var userPwd = optsObj.userpwd;

        var username = optsObj.username;

        var confirmPwd = optsObj.confirmpwd;

        var errorTripsObj = optsObj.errorTrips;

        var loginAuto = optsObj.loginAuto;

        var len = trim(userPwd.val()).length;

        if (0 == len) {

            errorTripsObj.html('请填写登录密码').css('visibility''visible');

            userPwd.focus();

            return false;

        else {

            if (len < 6 || len > 32) {

                errorTripsObj.html('密码应在6-32位字符内').css('visibility''visible');

                userPwd.focus();

                return false;

            else {

                errorTripsObj.css('visibility''hidden');

                if (isreg === 1) {

                    var reLen = trim(confirmPwd.val()).length;

                    if (0 == reLen) {

                        errorTripsObj.html('请填写重复登录密码').css('visibility''visible');

                        confirmPwd.focus();

                        return false;

                    else {

                        if (userPwd.val() != confirmPwd.val()) {

                            errorTripsObj.html('两次密码输入不一致').css('visibility''visible');

                            confirmPwd.focus();

                            return false; 

                        else {

                            return true;

                        }

                    }

                else {

                    if (loginAuto.attr("checked") === "checked") {

                        loginAuto.val("1");

                    else {

                        loginAuto.val("0");

                    }

                    $.ajax({

                        url : '/index.php?ac=account&op=login',

                        type : 'post',

                        dataType : 'json',

                        data : {

                            'username' : username.val(),

                            'userpwd' : userPwd.val(),

                            'rememberme' : loginAuto.val(),

                            'isajax' 'yes'

                        },

                        success : function (res) {

                            if (res.state == 0) {

                                errorTripsObj.html('用户名密码不匹配').css('visibility''visible');

                                userPwd.focus();

 

                                return false;

                            else {

                                if(callback) {

                                    location.href = "/home.htm" ;

                                }

                            }

                        }

                    });

                }

            }

        }

    }

 

    //检测是否接受协议

    function checkAccpet() {

        var optsObj = defaultOpts;

        var acceptObj = optsObj.accept;

        var errorTripsObj = optsObj.errorTrips;

        if (acceptObj.attr('checked')) {

            return true;

        else {

            errorTripsObj.html('请阅读并接受用户协议').css('visibility''visible');

            acceptObj.focus();

            return false;

        }

    }

 

    //验证码检测

    function checkCode() {

        var optsObj = defaultOpts;

        var checkcodeObj = optsObj.checkcode;

        var errorTripsObj = optsObj.errorTrips;

        if (checkcodeObj.length == 1 && "" == checkcodeObj.val()) {

            errorTripsObj.html('请输入验证码').css('visibility''visible');

            checkcodeObj.focus();

            return false;

        else {

            return true;

        }

    }

 

    //注册表单提交

    function regFormSubmit(e, data) {

        checkUserName(function (f) {

            var result, checkPwdResult;

            if (isreg === 1) {

                defaultOpts.regform.attr("action""/index.php?ac=account&op=registerhanlder");

                result = f && checkPwd() && checkAccpet() && checkCode();

                if (result) {

                    defaultOpts.regform.unbind('submit').submit();

                }

            else {

                checkPwd( f );

            }

 

        });

        if (!data) {

            return false;

        }

    }

 

    function bindEvent() {

        var optsObj = defaultOpts;

        optsObj.regform.submit($.proxy(regFormSubmit, this));

        optsObj.username.change(function () {

            checkUserName();

        })

        optsObj.userpwd.change($.proxy(checkPwd, this));

        if (isreg === 1) {

            optsObj.confirmpwd.change($.proxy(checkPwd, this));

        }

    }

 

    return {

        init : function (opts) {

            $.each(opts, function (i, n) {

                opts[i] = $("#" + n);

            });

            defaultOpts = $.extend(defaultOpts, opts);

            bindEvent();

        },

        checkEmailVlaue : function () {

            checkUserName();

        }

    };

})();

Copy after login

1

regAction.init({'regform':'regform','username':'email','errorTrips':'erroInfo','userpwd':'pwd','confirmpwd':'re-pwd','accept':'chkaccpet','checkcode':'checkcode','loginAuto':'login-auto','btnAction':'jAction'});//初始化

Copy after login

The above is the detailed content of Share jquery plug-in--form validation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to share Quark Netdisk to Baidu Netdisk? How to share Quark Netdisk to Baidu Netdisk? Mar 14, 2024 pm 04:40 PM

Quark Netdisk and Baidu Netdisk are very convenient storage tools. Many users are asking whether these two softwares are interoperable? How to share Quark Netdisk to Baidu Netdisk? Let this site introduce to users in detail how to save Quark network disk files to Baidu network disk. How to save files from Quark Network Disk to Baidu Network Disk Method 1. If you want to know how to transfer files from Quark Network Disk to Baidu Network Disk, first download the files that need to be saved on Quark Network Disk, and then open the Baidu Network Disk client. , select the folder where the compressed file is to be saved, and double-click to open the folder. 2. After opening the folder, click "Upload" in the upper left corner of the window. 3. Find the compressed file that needs to be uploaded on your computer and click to select it.

Detailed method to unblock using WeChat friend-assisted verification Detailed method to unblock using WeChat friend-assisted verification Mar 25, 2024 pm 01:26 PM

1. After opening WeChat, click the search icon, enter WeChat team, and click the service below to enter. 2. After entering, click the self-service tool option in the lower left corner. 3. After clicking, in the options above, click the option of unblocking/appealing for auxiliary verification.

How to share NetEase Cloud Music to WeChat Moments_Tutorial on sharing NetEase Cloud Music to WeChat Moments How to share NetEase Cloud Music to WeChat Moments_Tutorial on sharing NetEase Cloud Music to WeChat Moments Mar 25, 2024 am 11:41 AM

1. First, we enter NetEase Cloud Music, and then click on the software homepage interface to enter the song playback interface. 2. Then in the song playback interface, find the sharing function button in the upper right corner, as shown in the red box in the figure below, click to select the sharing channel; in the sharing channel, click the &quot;Share to&quot; option at the bottom, and then select the first &quot;WeChat Moments&quot; allows you to share content to WeChat Moments.

What is the Chrome plug-in extension installation directory? What is the Chrome plug-in extension installation directory? Mar 08, 2024 am 08:55 AM

What is the Chrome plug-in extension installation directory? Under normal circumstances, the default installation directory of Chrome plug-in extensions is as follows: 1. The default installation directory location of chrome plug-ins in windowsxp: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\Default\Extensions2. chrome in windows7 The default installation directory location of the plug-in: C:\Users\username\AppData\Local\Google\Chrome\User

Share three solutions to why Edge browser does not support this plug-in Share three solutions to why Edge browser does not support this plug-in Mar 13, 2024 pm 04:34 PM

When users use the Edge browser, they may add some plug-ins to meet more of their needs. But when adding a plug-in, it shows that this plug-in is not supported. How to solve this problem? Today, the editor will share with you three solutions. Come and try it. Method 1: Try using another browser. Method 2: The Flash Player on the browser may be out of date or missing, causing the plug-in to be unsupported. You can download the latest version from the official website. Method 3: Press the "Ctrl+Shift+Delete" keys at the same time. Click "Clear Data" and reopen the browser.

How to share files with friends on Baidu Netdisk How to share files with friends on Baidu Netdisk Mar 25, 2024 pm 06:52 PM

Recently, Baidu Netdisk Android client has ushered in a new version 8.0.0. This version not only brings many changes, but also adds many practical functions. Among them, the most eye-catching is the enhancement of the folder sharing function. Now, users can easily invite friends to join and share important files in work and life, achieving more convenient collaboration and sharing. So how do you share the files you need to share with your friends? Below, the editor of this site will give you a detailed introduction. I hope it can help you! 1) Open Baidu Cloud APP, first click to select the relevant folder on the homepage, and then click the [...] icon in the upper right corner of the interface; (as shown below) 2) Then click [+] in the &quot;Shared Members&quot; column 】, and finally check all

New features in PHP 8: Added verification and signing New features in PHP 8: Added verification and signing Mar 27, 2024 am 08:21 AM

PHP8 is the latest version of PHP, bringing more convenience and functionality to programmers. This version has a special focus on security and performance, and one of the noteworthy new features is the addition of verification and signing capabilities. In this article, we'll take a closer look at these new features and their uses. Verification and signing are very important security concepts in computer science. They are often used to ensure that the data transmitted is complete and authentic. Verification and signatures become even more important when dealing with online transactions and sensitive information because if someone is able to tamper with the data, it could potentially

Solve the problem that Discuz WeChat sharing cannot be displayed Solve the problem that Discuz WeChat sharing cannot be displayed Mar 09, 2024 pm 03:39 PM

Title: To solve the problem that Discuz WeChat shares cannot be displayed, specific code examples are needed. With the development of the mobile Internet, WeChat has become an indispensable part of people's daily lives. In website development, in order to improve user experience and expand website exposure, many websites will integrate WeChat sharing functions, allowing users to easily share website content to Moments or WeChat groups. However, sometimes when using open source forum systems such as Discuz, you will encounter the problem that WeChat shares cannot be displayed, which brings certain difficulties to the user experience.

See all articles