Home  >  Article  >  Backend Development  >  PHP Regular Determine Whether the Input Is a Letter Example Program_PHP Tutorial

PHP Regular Determine Whether the Input Is a Letter Example Program_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:00:091024browse

To determine whether it is a pure letter in php, we can directly use the regular /^[a-zA-Z]$/ to verify, including uppercase and lowercase letters. Students who need to know more can refer to it.

Upload the code

if (preg_match('/^[a-zA-Z]+$/',$str))
{
echo $str."is a letter";
}
else
{
echo $str."Not a letter";
}
The code is as follows
 代码如下 复制代码

header('Content-type: text/html; charset=utf-8');

$str = "dasdadsfsadASDSADS";

if (preg_match('/^[a-zA-Z]+$/',$str))
{
echo $str."是字母";
}
else
{
echo $str."不是字母";
}

?>

Copy code

 代码如下 复制代码
preg_match('/^[a-zA-Z]+$/',$str)

header('Content-type: text/html; charset=utf-8');

$str = "dasdadsfsadASDSADS";
代码如下 复制代码

if(preg_match("/^d*$/", "4312"))
{
echo "全数字
";
}

if(preg_match("/^[a-z]*$/i", "fdsFDfd"))
{
echo "全字母
";
}

if(preg_match("/^[a-zd]*$/i", "fd4fd34"))
{
echo "有数字有字母
";
}

?>

This is the code Returns TRUE if it is a letter, otherwise returns FALSE Other judgments
The code is as follows Copy code
if(preg_match("/^d*$/", "4312"))
{
echo "All numbers
";
} if(preg_match("/^[a-z]*$/i", "fdsFDfd"))
{
echo "Full letters
";
}
if(preg_match("/^[a-zd]*$/i", "fd4fd34"))
{
echo "There are numbers and letters
";
}
http://www.bkjia.com/PHPjc/631265.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631265.htmlTechArticleTo determine whether it is a pure letter in php, we can directly use the regular /^[a-zA-Z]$/ Come and verify, including uppercase and lowercase letters. Students who need to know more can refer to it. The code above is as follows...
Statement:
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