php验证用户名是否以字母开头与验证密码实例
本文实例讲述了php验证用户名是否以字母开头与验证密码的方法。分享给大家供大家参考。具体如下:
验证用户名是否以字母开头与验证密码只能为数字和字母的组合代码,三种常用验证函数:验证邮箱地址格式 ,验证密码只能为数字和字母的组合以及验证用户名是否以字母开头代码,这是用户注册时或提交表单时会用的。
代码如下:
function is_email($email)
{
if (preg_match("/[a-za-z0-9]+@[a-za-z0-9]+.[a-z]{2,4}/",$email,$mail))
{
return true;
}
else
{
return false;
}
}
/**
* 验证用户名是否以字母开头
*/
function is_user_name($user)
{
if (preg_match("/^[a-za-z]{1}([a-za-z0-9]|[._]){3,19}$/",$user,$username))
{
return true;
}
else
{
return false;
}
}
/**
* 验证密码只能为数字和字母的组合
*/
function is_psd($psd)
{
if (preg_match("/^(w){4,20}$/",$psd,$password))
{
return true;
}
else
{
return false;
}
}
希望本文所述对大家的正则表达式学习有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment