2
我正在使用symfony 1.4教义。我有一个可以验证电话号码的代码,这里的代码是:(基于这个网站“http://jasonswett.net/blog/how-to-validate-and-sanitize-a-phone-number-in-symfony/” )自定义手机验证器不工作symfony
我把它粘贴在lib文件夹中。
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;
}
}
然后,我创建了这个代码在我的表单文件夹
lib/form/doctrine/reservation/reservationApplicationForm.class.php
$this->validatorSchema['telephone'] = new myValidatorPhone(array(
'required' => false,
));
但是当我运行程序出现错误:
Fatal error: Class 'myValidatorPhone' not found in C:\www\project\reservation\lib\form\doctrine\reservationApplicationForm.class.php on line 36
基于网站的代码适用于1.4我现在正在使用它。但我不知道为什么我会遇到致命错误。
谢谢!!有效 – Martin