PHP Common validation Code

Source: Internet
Author: User

//Function Name: Checkmoney ($C _money)     
//function: Check whether the data is 99999.99 format     
//Parameter Number: $C _money (number to be detected)     
//Return value: Boolean     
//Memo: No      
//-----------------------------------------------------------------------------------     
-------    

  code is as follows copy code
function Checkmoney ($C _money)     
{    
if (!ereg ("^[0-9][.] [0-9]$, $C _money)] return false;    
return true;    
}     


//-----------------------------------------------------------------------------------     
-------   
  
  
//------------------------------------- ----------------------------------------------    
-------    
/ /function Name: checkemailaddr ($C _mailaddr)     
//function: To determine if it is a valid mailing address     
//parameter: $ C_MAILADDR (email address to be detected)     
//Return value: Boolean     
//NOTE: no    & nbsp
//-----------------------------------------------------------------------------------     
-------    

  code is as follows copy code
function CHECKEMAILADDR ($C _mailaddr)     
{    
if (!eregi ("^[_a-z0-9-]+") (. [ _a-z0-9-]+) *@[a-z0-9-]+ (. [ a-z0-9-]+) *$ ",    
$C _mailaddr)")     
//(!ereg ("^[_a-za-z0-9-]+" (). [ _a-za-z0-9-]+) *@[_a-za-z0-9-]+ (. [ _a-za-z0-9-]+) *$ ",    
$c _mailaddr)"     
{     
Return false;    
}    
Return true;   & nbsp
}    


//-----------------------------------------------------------------------------------     
-------   
  
  
//------------------------------------- ----------------------------------------------    
-------    
/ /function Name: checkwebaddr ($C _weburl)     
//function: To determine if it is a valid URL     
//Parameter: $C _ Weburl (address to be detected)     
//Return value: Boolean     
//Memo: No     
//-----------------------------------------------------------------------------------     
-------    

  code is as follows copy code
function CHECKWEBADDR ($C _weburl)     
{    
if (!ereg ("^http://[_a-za-z0-9- ]+(. [_a-za-z0-9-]+) *$ ", $C _weburl))     
{    
Return false;     
}    
return true;    
}   & nbsp


//-----------------------------------------------------------------------------------     
-------   
  
  
//------------------------------------- ----------------------------------------------    
-------    
/ /function Name: Checkempty ($C _char)     
//function: Determine if the string is null     
//Parameter: $C _ char (string to be detected)     
//Return value: Boolean     
//Memo: No     
//-----------------------------------------------------------------------------------     
-------    

/tbody>
  code is as follows copy code
function Checkemptystring ($C _char)     
{    
if (!is_string ($C _char)) return false; is a string type     
if (emptyempty ($C _char)) return false;//is set     
if ($C _char== ') return false; Is null     
return true;    
}    


//-----------------------------------------------------------------------------------     
-------   
  
//----------------------------------------------------- ------------------------------    
-------    
// Function name: Checklengthbetween ($C _char, $I _len1, $I _len2=100)     
//function: To determine whether the string    in the specified length   
//Parameters: $C _char (string to be detected)     
//$I _len1 (lower bound of target string length)     
//$I _len2 (upper limit of target string length)     
//Return value: Boolean     
//Memo: No   & nbsp; 
//-----------------------------------------------------------------------------------     
-------    

  code is as follows copy code
function Checklengthbetween ($C _cahr, $I _len1, $I _len2=100)     
{    
$C _ Cahr = Trim ($C _cahr);    
if (strlen ($C _cahr) < $I _len1) return false;   & nbsp
if (strlen ($C _cahr) > $I _len2) return false;    
return true;     br>}    


//-----------------------------------------------------------------------------------     
-------   
  
//----------------------------------------------------- ------------------------------    
-------    
//Function Name: CheckUser ($ C_user)     
//function: To determine whether the legal user name     
//parameter: $C _user (user name to be detected)      
//Return value: Boolean     
//Memo: No     
//--------------- --------------------------------------------------------------------    
-------     

  code is as follows copy code
function CheckUser ($C _user)     
{    
if (! Checklengthbetween ($C _user, 4)) return false; Width Check     
if (!ereg ("^[_a-za-z0-9]*$", $C _user)) return false;//special character validation      
Return true;    
}    

//-----------------------------------------------------------------------------------     
-------   
  
//----------------------------------------------------- ------------------------------    
-------    
// Function name: Checkpassword ($C _passwd)     
//function: To determine whether a valid user password     
//Parameter: $C _ passwd (password to be detected)     
//Return value: Boolean     
//Memo: No     
//-----------------------------------------------------------------------------------     
-------    

  code is as follows copy code
function Checkpassword ($C _passwd)     
{    
if (! Checklengthbetween ($C _passwd, 4)) return false; Width detection     
if (!ereg ("^[_a-za-z0-9]*$", $C _passwd)) return false;//special character detection      
Return true;  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.