Home  >  Article  >  php教程  >  弄了个检测传输的参数是否为数字的Function

弄了个检测传输的参数是否为数字的Function

WBOY
WBOYOriginal
2016-06-13 12:35:431246browse

/*判断专传输数据是否为数字 
用正则表达式判断输入的数字是否合法 
调用:checknum(参数1,参数2) 

*/ 

复制代码 代码如下:

function checknum($id,$say)  
{  
            $inid=$id;  
            if(!ereg("^(-{0,1}|\+{0,1})[0-9]+(\.{0,1}[0-9]+)$",$inid))  
        {  
        echo $say.",入口:"."".$inid."";  
            exit;  
        }  
}  



调用 

复制代码 代码如下:

$tid="111fff";  
checknum($tid,"数字非法")  
?>  

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