php驗證用戶名是否以字母開頭的例子
php中驗證用戶名我們通常使用了正則函數來操作了,下文整理的是幾個常用的驗證用戶名的函數,希望這些函數可以幫助到各位.驗證用戶名是否以字母開頭與驗證密碼只能為數字和字母的組合代碼,三種常用驗證函數:驗證郵箱地址格式 ,驗證密碼只能為數字和字母的組合以及驗證用戶名是否以字母開頭代碼,這是用戶註冊時或提交表單時會用的。
代碼如下:
php代碼:
function is_email($email)
{
if (preg_match("/+@+.{2,4}/",$email,$mail))
{
return true;
}
else
{
return false;
}
}
驗證用戶名是否以字母開頭
function is_user_name($user)
{
if (preg_match("/^{1}(|[._]){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;
}
}
頁:
[1]