如何检查是否变量是在PHP字母或数字?
答
取决于你如何定义数字,您将使用下列功能之一:
随着第一个,数字被定义为(引用):
数字串包括可选 标志的,任意数量的数字,可选 小数部分和指数可选部分 。
虽然,与第二个,你会(引用):
检查是否所有在 提供的一串字符,文本,是数字
而且,对于字母,您将有兴趣:
报价:
检查是否所有的 提供的字符串中的字符,文字是字母。 在标准C语言环境字母 只是
[A-Za-z]
而且,如@Long耳朵在他的评论指出的那样,如果你要同时检查单杆,你会发现ctype_alnum()
功能(引用):
检查是否所有在 提供的字符串,文本的字符,是 字母数字。
在任何情况下,你可能想看看的Ctype functions的完整列表。
+0
对于可以是字母或数字,'ctype_alnum',或者如果你需要支持unicode,那么'preg_match('/^[\ pL \ d] + \ z /',$ s)' – 2011-03-15 05:41:48
答
使用is_numeric功能:
is_numeric("42"); // true
is_numeric(1337); // true
is_numeric("1e4"); // true
is_numeric("not numeric"); // false
is_numeric(Array()); // false
is_numeric(9.1); // true
答
you quick test the input val by if numeric or alpha`enter code here`
using this php function
if(ctype_alnum($eafrik)){
echo "is alphatnumeric";
}else{
echo "is not alphanumeric"
}
http://stackoverflow.com/questions/1969464/how-to-check-if-a-variable-is-a-numeric-value – 2011-03-15 05:38:41