只允许字符串中的某些字符 [英] Only allowing certain characters in string
本文介绍了只允许字符串中的某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找一种方法来创建一个函数来检查一个字符串中是否包含除小写字母和数字之外的任何内容,以及是否返回false。我在互联网上搜索,但我所能找到的是旧的方法,要求您使用现在在PHP5中已弃用的函数。 解决方案
pre> 函数check_input($ text){
if(preg_match(/ [^ a-z0-9] /,$ text)){
return false ;
}
else {
return true;
}
}
I have been looking for a way to create a function to check if a string contains anything other than lower case letters and numbers in it, and if it does return false. I have searched on the internet but all I can find is old methods that require you to use functions that are now deprecated in PHP5.
解决方案
function check_input( $text ) {
if( preg_match( "/[^a-z0-9]/", $text ) ) {
return false;
}
else {
return true;
}
}
这篇关于只允许字符串中的某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文