Home Daily Programming HTML Knowledge jQuery form verification submission: front-end verification 2 (image, text + video)

jQuery form verification submission: front-end verification 2 (image, text + video)

Oct 23, 2018 am 10:12 AM

This article mainly introduces in detail the specific method of jQuery to implement form verification submission.

In the previous article [jQuery form verification submission: front-end verification one], we have briefly listed the specific method codes for jQuery to implement form verification submission. So this section will introduce to you in detail the specific method of jQuery to implement form verification submission.

The main code examples are as follows:

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

<!DOCTYPE>

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>jQuery用户注册表单验证代码</title>

    <link href="css/jq22.css" rel="stylesheet" type="text/css"/>

    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>

    <script language=&#39;javascript&#39; src="js/jq22.js"></script>

</head>

<body>

<div class=&#39;body_main&#39;>

 

    <div class=&#39;index_box&#39; style=&#39;margin-top:20px;&#39;>

        <div style="position:fixed;color:red;margin:70px 0 0 450px;font-size:16px;Z-index:100;display:block;"

             id="hint"></div>

        <div class=&#39;box_title&#39;>

            <div class=&#39;text_content&#39;>

                <h1>jQuery用户注册表单验证代码</h1>

            </div>

        </div>

        <div class=&#39;box_main&#39;>

            <div id="register" class="register">

                <form id="form" action="check1.php" method="post" onSubmit="return check();">

                    <div id="form_submit" class="form_submit">

                        <div class="fieldset">

                            <div class="field-group">

                                <label class="required title">手机号码</label>

                                <span class="control-group" id="mobile_input">

                <div class="input_add_long_background">

                  <input class="register_input" type="text" id="mobile" name="mobile" maxLength="11" value=""

                         onblur="__changeUserName(&#39;mobile&#39;);">

                </div>

                </span>

                                <label class="tips">仅用于发送服务开通与到期提醒以及紧急故障方便联系到您,绝对保密</label>

                            </div>

                            <div class="field-group">

                                <label class="required title">邮箱</label>

                                <span class="control-group" id="email_input">

                <div class="input_add_long_background">

                  <input class="register_input" type="text" id="email" name="email" maxLength="50" value=""

                         onblur="__changeUserName(&#39;email&#39;);">

                </div>

                </span>

                                <label class="tips">请输入您常用的邮箱</label>

                            </div>

                            <div class="field-group">

                                <label class="required title">设置密码</label>

                                <span class="control-group" id="password1_input">

                <div class="input_add_long_background">

                  <input class="register_input" type="password" id="password1" name="password1" maxLength="20" value=""

                         onblur="checkPwd1(this.value);"/>

                </div>

 

                </span>

                                <label class="tips">请使用6~20个英文字母(区分大小写)、符号或数字</label>

                            </div>

                            <div class="field-group">

                                <label class="required title">确认密码</label>

                                <span class="control-group" id="password2_input">

                <div class="input_add_long_background">

                  <input class="register_input" type="password" id="password2" name="password2" maxLength="20" value=""

                         onblur="checkPwd2(this.value);"/>

                </div>

 

                </span>

                                <label class="tips">请输入确认密码,要和上面的密码一致</label>

                            </div>

                        </div>

                    </div>

                    <div id="div_submit" class="div_submit">

                        <div class=&#39;div_submit_button&#39;>

                            <input id="submit" type="submit" value="注册" class=&#39;button_button disabled&#39;>

                        </div>

                    </div>

                </form>

            </div>

            <script type="text/javascript">

                function __changeUserName(of) {

                    var username = $(&#39;#&#39; + of).val();

                    if (of == &#39;email&#39;) {

                        if (username.search(/^[\w\.+-]+@[\w\.+-]+$/) == -1) {

                            showTooltips(&#39;email_input&#39;, &#39;请输入正确的Email地址&#39;);

                            return;

                        }

                    }

                    else {

                        if (username == &#39;&#39; || !isMobilePhone(username)) {

                            showTooltips(&#39;mobile_input&#39;, &#39;请输入正确的手机号码&#39;);

                            return;

                        }

                    }

                }

 

                function checkPwd1(pwd1) {

                    if (pwd1.search(/^.{6,20}$/) == -1) {

                        showTooltips(&#39;password1_input&#39;, &#39;密码为空或位数太少&#39;);

                    } else {

                        hideTooltips(&#39;password1_input&#39;);

                    }

                }

 

                function checkPwd2(pwd2) {

                    var pas1 = $(&#39;#password1&#39;).val();

                    if (pwd2.search(/^.{6,20}$/) == -1) {

                        showTooltips(&#39;password2_input&#39;, &#39;密码为空或位数太少&#39;);

                    }

                    if (pwd2 != pas1) {

                        showTooltips(&#39;password2_input&#39;, &#39;两次密码不一致&#39;);

                    }

                }

 

                function check() {

                    hideAllTooltips();

                    var ckh_result = true;

                    // if ($(&#39;#email&#39;).val() == &#39;&#39; || !isEmail($(&#39;#email&#39;).val())) {

                    //     showTooltips(&#39;email_input&#39;, &#39;请输入正确的Email地址&#39;);

                    //     ckh_result = false;

                    // }

                    if ($(&#39;#password1&#39;).val() == &#39;&#39;) {

                        showTooltips(&#39;password1_input&#39;, &#39;密码不能为空&#39;);

                        ckh_result = false;

                    }

                    if ($(&#39;#password2&#39;).val() == &#39;&#39;) {

                        showTooltips(&#39;password2_input&#39;, &#39;确认密码不能为空&#39;);

                        ckh_result = false;

                    }

                    if ($(&#39;#password2&#39;).val() != $(&#39;#password1&#39;).val()) {

                        showTooltips(&#39;password2_input&#39;, &#39;两次密码不一致&#39;);

                        ckh_result = false;

                    }

                    if ($(&#39;#mobile&#39;).val() == &#39;&#39; || !isMobilePhone($(&#39;#mobile&#39;).val())) {

                        showTooltips(&#39;mobile_input&#39;, &#39;手机号码不正确&#39;);

                        ckh_result = false;

                    }

 

                    return ckh_result;

                }

 

                function isMobilePhone(value) {

                    if (value.search(/^(\+\d{2,3})?\d{11}$/) == -1) {

                        return false;

                    }

                    else

                        return true;

                }

 

                function isEmail(value) {

                    if (value.search(/^[\w\.+-]+@[\w\.+-]+$/) == -1) {

                        return false;

                    }

                    else

                        return true;

                }

            </script>

        </div>

        <div class=&#39;box_bottom&#39;></div>

    </div>

</div>

 

</body>

</html>

Copy after login

In the above code, we simply wrote a form and submitted the front-end data to check1.php. Submit The method is post, and a click event is given to the form.

When we click submit, a series of information judgments will be made. And when we do not click to register, that is, the click event is not triggered, there will also be a judgment.

Such as the __changeUserName method in the code. In this method, we first use regular expressions to determine whether the email format is correct and whether the mobile phone number is correct. And in the checkPwd1 and checkPwd2 methods, determine whether the password meets the requirements and is the same as the first password. These methods are all verifications that occur when the registration button is not clicked.

Of course, these judgments are not enough, so we need to write a verification that will occur when clicking to register, such as the check method in the above code, in which we judge each field (required in the background) fields need to be verified).

In addition to the above verification method of click registration, we can also bind an event to the click registration button to determine verification. I won’t go into details here.

The js and css codes involved are all in the previous article [jQuery form verification submission: front-end verification one]. Friends who need it can refer to it.

This article is about jQuery's method of implementing form verification and submission. I hope it will be helpful to friends in need!

If you want to learn more about front-end related knowledge, you can follow the PHP Chinese website jQuery video tutorial, JavaScript video tutorial, Bootstrap tutorialWait for related video tutorials, everyone is welcome to refer to and learn!

The above is the detailed content of jQuery form verification submission: front-end verification 2 (image, text + video). 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)