Home >Backend Development >PHP Tutorial >PHP general detection function set (2)_PHP tutorial
// Function name: CheckWebAddr($C_weburl)
// Function: Determine whether it is a valid URL
// Parameter: $C_weburl (URL to be detected)
// Return value: Boolean value
// Remarks: None
//------------------------------------------------ ---------------------------------------------
---- ---
function CheckWebAddr($C_weburl)
{
if (!ereg("^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0- 9-]+)*$", $C_weburl))
{
return false;
}
return true;
}
//-------- -------------------------------------------------- --------------------------
-------
//---- -------------------------------------------------- -----------------------------
-------
// Function name: CheckEmpty($ C_char)
// Function: Determine whether the string is empty
// Parameter: $C_char (string to be detected)
// Return value: Boolean value
// Remarks: None
//--------------------------------------------- -------------------------------------
------
function CheckEmptyString($C_char)
{
if (!is_string($C_char)) return false; //Whether it is a string type
if (empty($C_char)) return false; //Whether it has been Set
if ($C_char==) return false; //Whether it is empty
return true;
}
//--------------- -------------------------------------------------- ------------------
-------
//------------- -------------------------------------------------- ------------------
-------
// Function name: CheckLengthBetween($C_char, $I_len1, $I_len2=100)
// Function: Determine whether it is a string within the specified length
// Parameter: $C_char (string to be detected)
// $I_len1 (lower limit of the target string length)
/ / $I_len2 (the upper limit of the target string length)
// Return value: Boolean value
// Remarks: None
//---------------- -------------------------------------------------- ------------------
-------
function CheckLengthBetween($C_cahr, $I_len1, $I_len2=100)
{
$C_cahr = trim($C_cahr);
if (strlen($C_cahr) < $I_len1) return false;
if (strlen($C_cahr) > $I_len2) return false;
return true;
}
//------------------------------------------ -----------------------------------------------
--- ----
//----------------------------------------- ---------------------------------------------
-- -----
// Function name: CheckUser($C_user)
// Function: Determine whether it is a legal user name
// Parameter: $C_user (user name to be detected)
// Return value: Boolean value
// Remarks: None
//-------------------------------- -------------------------------------------------- ---
-------
function CheckUser($C_user)
{
if (!CheckLengthBetween($C_user, 4, 20)) return false; //Width check
if (!ereg("^[_a-zA-Z0-9]*$", $C_user)) return false; //Special character check
return true;
}
//- -------------------------------------------------- --------------------------------
------
// -------------------------------------------------- ----------------------------------
-------
// Function name :CheckPassword($C_passwd)
// Function: Determine whether it is a legal user password
// Parameter: $C_passwd (password to be detected)
// Return value: Boolean value
// Remarks :None
//------------------------------------------------ ----------------------------------------
-------
function CheckPassword($C_passwd)
{
if (!CheckLengthBetween($C_passwd, 4, 20)) return false; //Width detection
if (!ereg("^[_a-zA -Z0-9]*$", $C_passwd)) return false; //Special character detection
return true;
}
//-------------------------- -------------------------------------------------- ------------------
-------
//------------- -------------------------------------------------- --------------------
-------