Php 自定义电话验证程序不工作symfony
我用的是symfony1.4理论。我有一个可以验证电话号码的代码这是代码:(基于此网站)http://jasonswett.net/blog/how-to-validate-and-sanitize-a-phone-number-in-symfony/)) 我把它贴在了lib文件夹上Php 自定义电话验证程序不工作symfony,php,validation,symfony-1.4,Php,Validation,Symfony 1.4,我用的是symfony1.4理论。我有一个可以验证电话号码的代码这是代码:(基于此网站)http://jasonswett.net/blog/how-to-validate-and-sanitize-a-phone-number-in-symfony/)) 我把它贴在了lib文件夹上 apps/frontend/lib/myValidatorPhone.class.php <?php /** * myValidatorPhone validates a phone number.
apps/frontend/lib/myValidatorPhone.class.php
<?php
/**
* myValidatorPhone validates a phone number.
*
* @author Jason Swett (http://jasonswett.net/how-to-validate-and-sanitize-a-phone-number-in-symfony/)
*/
class myValidatorPhone extends sfValidatorBase
{
protected function doClean($value)
{
$clean = (string) $value;
$phone_number_pattern = '/^(\((\d{3})\)|(\d{3}))\s*[-\.]?\s*(\d{3})\s*[-\.]?\s*(\d{4})$/';
if (!$clean && $this->options['required'])
{
throw new sfValidatorError($this, 'required');
}
// If the value isn't a phone number, throw an error.
if (!preg_match($phone_number_pattern, $clean))
{
throw new sfValidatorError($this, 'invalid', array('value' => $value));
}
// Take out anything that's not a number.
$clean = preg_replace('/[^0-9]/', '', $clean);
// Split the phone number into its three parts.
$first_part = substr($clean, 0, 3);
$second_part = substr($clean, 3, 3);
$third_part = substr($clean, 6, 4);
// Format the phone number.
$clean = '('.$first_part.') '.$second_part.'-'.$third_part;
return $clean;
}
}
但是当我运行程序时,我得到了错误:
致命错误:在中找不到类“myValidatorPhone”
C:\www\project\reservation\lib\form\doctor\reservationApplicationForm.class.php
第36行
基于这个网站,这段代码在我现在使用的1.4版本上运行。但我不知道为什么会出现致命错误。在lib文件夹中创建文件夹验证器,并将验证器放入lib/validator/myValidatorPhone.class.php中
lib/form/doctrine/reservation/reservationApplicationForm.class.php
$this->validatorSchema['telephone'] = new myValidatorPhone(array(
'required' => false,
));