Here's one I did for validating phone numbers.
/* ---------------------------------------------------------
DATE: 5-2001
PURPOSE: Check the given "stripped" phone number for validity.
PARAMETERS: the phone number
RETURNS: If Ok, return -1. Otherwise, return the phone number length.
Last modified: 7-21-01
Notes:
--------------------------------------------------------- */
function CheckPhoneNumLen($phone_num)
{
$len = strlen($phone_num);
if ($len != 10) // e.g. "2027773238"
{
return $len;
}
else
{
return -1; // true
}
}
So what's a "stripped" phone number? One with only numerics, e.g., no dashes or parens.
/* ---------------------------------------------------------
Remove any non-numbers from given phone num
------------------------------------------------------- */
function StripPhoneNum($phone_num)
{
$len = strlen($phone_num);
for ($i = 0; $i < $len; $i++)
{
$a = $phone_num[$i];
if ( ($a < "0") || ($a > "9") )
{
$striped_phone_num .= "";
}
else
$striped_phone_num .= $phone_num[$i];
}
return $striped_phone_num;
}
I think you get the idea.
Hope that helps.