如何判断字符串是否为纯字母

Posted void9main

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何判断字符串是否为纯字母相关的知识,希望对你有一定的参考价值。

function checkStrIsLetter($str){
		$letteraArr = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
		$letterAArr = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ");
		//字母表
		$letter = array_merge($letteraArr,$letterAArr);
		//分割字符
		$strArr = str_split($str);
		//循环判断
		if(!empty($strArr)){
			foreach($strArr as $key=>$val){
				if(!in_array($val,$letter)){
					return "no";
					exit;
				}
			}
		}else{
			return "no";
		}
		return "yes";
	}

  

以上是关于如何判断字符串是否为纯字母的主要内容,如果未能解决你的问题,请参考以下文章

awk 如何判断一个字符串是不是为纯数字?

如何用BAT判断文本中的字符串是不是为纯数字,即没有字母,并去执行两个相应的操作

自定义一个方法判断一个字符串是不是为纯数字

列表元组字符串方法,字符串的编码

Java中判断某一字符串是否包含数字字母和中文

java中判断字符串是不是为纯数字