Home Backend Development PHP Tutorial Sample code for php user registration information verification using regular expressions

Sample code for php user registration information verification using regular expressions

Jul 07, 2017 am 10:25 AM
php User registration expression

各种网页脚本也都常用“正则表达式”(regular expression)对我们信息进行验证,判断是否合法,本文为大家介绍了php用户注册验证正则表达式,需要的朋友可以参考下

下面这个正则验证用户名的方法原则是这样的用户名必须是由字母带数字带定划线组成了,下面一起来看看例子吧.

1.检查用户名是否符合规定“两位以上的字母,数字,或者下划线”,代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

/**

 * 检查用户名是否符合规定

 *

 * @param STRING $username 要检查的用户名

 * @return TRUE or FALSE

 */

function is_username($username)

{

$strlen = strlen($username);

if (!preg_match("/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/",

$username)) //开源软件:phpfensi.com

{

return false;

} elseif (20 < $strlen || $strlen < 2)

{

return false;

}

return true;

}

Copy after login

两位以上的字母,数字,或者下划线:^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$.

注:在这里,字母是a-z,A-Z,以及从127 到255(0x7f-0xff)的 ASCII 字符

2、密码:6—20位,由字母、数字组成,代码如下:

1

2

3

4

5

6

7

function isPWD($value,$minLen=5,$maxLen=16){

$match='/^[\\~!@#$%^&*()-_=+|{}\[\],.?\/:;\'\"\d\w]{'.$minLen.','.$maxLen.'}$/';

$v = trim($value);

if(emptyempty($v))

return false;

return preg_match($match,$v);

}

Copy after login

3、email验证,代码如下:

1

2

3

4

5

6

7

8

function isEmail($value,$match='/^[\w\d]+[\wd-.]*@[w\d-.]+\.[\w\d]{2,10}$/i')

 

{

$v = trim($value);

if(emptyempty($v))

return false;

return preg_match($match,$v);

}

Copy after login

The above is the detailed content of Sample code for php user registration information verification using regular expressions. 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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

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 Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

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

CakePHP File upload

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

Discuss CakePHP

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

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

CakePHP Quick Guide

DeepSeek official website entrance and latest promotional activities DeepSeek official website entrance and latest promotional activities Feb 19, 2025 pm 05:15 PM

DeepSeek official website entrance and latest promotional activities

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

CakePHP Creating Validators

See all articles