<?
CModule::IncludeModule("form");
IncludeModuleLangFile(__FILE__);
class CFormValidatorPhonesNumber
{
function GetDescription()
{
return array(
"NAME" => "phones_number",
"DESCRIPTION" => "Номера телефонов",
"TYPES" => array("text", "textarea"),
"HANDLER" => array("CFormValidatorPhonesNumber", "DoValidate")
);
}
function DoValidate($arParams, $arQuestion, $arAnswers, $arValues)
{
global $APPLICATION;
$arEnabledSymbols = array(" ", ",", "-", "(", ")", ";", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+");
foreach ($arValues as $value)
{
$isCorrect = true;
for($i = 0; $i<strlen($value);$i++)
{
if(!in_array($value[$i], $arEnabledSymbols))
{
$isCorrect = false;
break;
}
}
if(!$isCorrect)
{
$APPLICATION->ThrowException("Поле \"#FIELD_NAME#\": заполненно некорректно!");
return false;
}
}
return true;
}
}
AddEventHandler("form", "onFormValidatorBuildList", array("CFormValidatorPhonesNumber", "GetDescription"));
?>
|