Home Backend Development PHP Tutorial PHP form validation corresponds to jquery-validate plug-in

PHP form validation corresponds to jquery-validate plug-in

Apr 21, 2018 pm 04:52 PM
php plug-in

The content of this article is about the jquery-validate plug-in corresponding to PHP form verification. It has a certain reference value. Now I share it with you. Friends in need can refer to it


Direct code. If you don’t understand the parameters, you can refer to the jquery-validate plug-in

Learning recommendation:
"thinkphp5 classic case" http://www.kancloud.cn/duerhong/rumen/308144
thinkphp elite group :536633782



##

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

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

<?php

/*

 

 

*/

namespace Vendor\Mylib;

class DbValidate{

    function __construct()

    {

    }

    // 必填

  function v_required($value,$limit=true)

  {

        if ($limit) {

            if (isset($value) and !empty($value)) {

                return true;

            }

            else{

                return false;

            }

        }

        else{

            return true;

        }

  }

 

 

    // 邮箱

    public function v_email($value,$limit=true)

    {

        if ($limit) {

            if ($this->is_email($value)) {

                return true;

            }

            else{

                return false;

            }

        }

        else{

            return true;

        }

    }

 

 

    // 手机号码

    public function v_mobile($value,$limit=true)

    {

        if ($limit) {

            if ($this->is_mobile($value)) {

                return true;

            }

            else{

                return false;

            }

        }

        else{

            return true;

        }

    }

 

 

 

 

 

 

 

 

    // url

    public function v_url($value,$limit=true)

    {

        if ($limit) {

            if ($this->is_url($value)) {

                return true;

            }

            else{

                return false;

            }

        }

        else{

            return true;

        }

    }

 

 

    // 是否数字

    public function v_number($value,$limit=true)

    {

        if ($limit) {

            if (is_numeric($value)) {

                return true;

            }

            else{

                return false;

            }

        }

        else{

            return true;

        }

    }

 

 

    // 是否整数

    public function v_digits($value,$limit=true)

    {

        if ($limit) {

            if (is_digits($value)) {

                return true;

            }

            else{

                return false;

            }

        }

        else{

            return true;

        }

    }

    //检测合法后缀名

    public function v_accept($value,$limit=true)

    {

        $list=explode('.',$value);

        $ext=end($list);

        $extdot='.'.$ext;

        if ($limit==$ext or $limit==$extdot) {

            return true;

        }

        else{

            return false;

        }

    }

 

 

    // 字符最大长度 只判断英文 无法验证中文

    public function v_maxlength($value,$limit=true)

    {

      $len=strlen($value);

      if ($len<=$limit) {

        return true;

      }

      else{

        return false;

      }

    }

    // 最小字符长度 注意只判断英文,数字。无法验证中文

    public function v_minlength($value,$limit=true)

    {

      $len=strlen($value);

      if ($len>=$limit) {

        return true;

      }

      else{

        return false;

      }

    }

 

 

    // 输入值长度区间

    public function v_rangelength($value,$limit=true)

    {

      $list=explode(',',$limit);

      $len=strlen($value);

      $min=$list[0];

      $max=$list[1];

      if ($len>=$min and $len<=$max) {

        return true;

      }

      else{

        return false;

      }

    }

    // 输入值区间

    function v_range($value,$limit=true)

    {

      $list=explode(',',$limit);

      $min=$list[0];

      $max=$list[1];

      if ($value>=$min and $value<=$max) {

        return true;

      }

      else{

        return false;

      }

    }

 

 

    // 输入的最大值

    function v_max($value,$limit=true)

    {

      if ($value<=$limit) {

        return true;

      }

      else{

        return false;

      }

    }

 

 

    // 输入的最小值

    function v_min($value,$limit=true)

    {

        if ($value>=$limit) {

            return true;

        }

        else{

            return false;

        }

    }

 

 

 

 

    // ------------------ -公用验证-----=========================--------

    // 是否邮箱

    function is_email($email)

    {

        if(!filter_var($email, FILTER_VALIDATE_EMAIL))

         {

            return false;

         }

        else

         {

            return true;

         }

    }

    //验证手机号码

    function is_mobile($str){

        if(preg_match("/1[3458]{1}\d{9}$/",$str)){

        return true;

        }else{

          return false;

        }

    }

 

 

    //验证url地址

    function is_url($str){

      return preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\’:+!]*([^<>\"])*$/", $str);

    }

 

 

 

 

    function is_date($date)

    {

        //匹配日期格式

        if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts))

        {

            //检测是否为日期

            if(checkdate($parts[2],$parts[3],$parts[1])){

              return true;

            }

            else{

                return false;

            }

        }

        else{

          return false;

        }

    }

 

 

    function is_digits($str){

        if (is_numeric($str)) {

          if (!strstr($str, '.')) {

            return true;

          }

        else{

          return false;

        }

        }

      else{

        return false;

      }

    }

 

 

    //检测后缀名 explode

    public function is_ext($str)

    {

        $file_list=explode('.');

    }

 

}

?>

Copy after login


jquery-validate plug-in parameters


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

jqueryvalidation 常用插件 *代表php暂时不支持

required:true   必须输入的字段。

remote:"check.php"    使用 ajax 方法调用 check.php 验证输入值。

email:true  必须输入正确格式的电子邮件。

url:true    必须输入正确格式的网址。

date:true   必须输入正确格式的日期。日期校验 ie6 出错,慎用。

dateISO:true    必须输入正确格式的日期(ISO),例如:2009-06-23,1998/01/22。只验证格式,不验证有效性。 ***

number:true 必须输入合法的数字(负数,小数)。

digits:true 必须输入整数。

creditcard: 必须输入合法的信用卡号。 ***

equalTo:"#field"  输入值必须和 #field 相同。 ***

accept: 输入拥有合法后缀名的字符串(上传文件的后缀)。

maxlength:5 输入长度最多是 5 的字符串(汉字算一个字符)。

minlength:10    输入长度最小是 10 的字符串(汉字算一个字符)。

rangelength:[5,10]  输入长度必须介于 5 和 10 之间的字符串(汉字算一个字符)。

range:[5,10]    输入值必须介于 5 和 10 之间。

max:5   输入值不能大于 5。

min:10  输入值不能小于 10。

Copy after login

Related recommendations:

php form to prevent repeated submission (anti-csrf vulnerability)










#

The above is the detailed content of PHP form validation corresponds to jquery-validate plug-in. 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 Article Tags

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)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles