2
votes

I'm using symfony 1.4 doctrine. I have a code that can validate phone numbers here's the code:(Based on this website "http://jasonswett.net/blog/how-to-validate-and-sanitize-a-phone-number-in-symfony/")

I pasted it on lib folder.

 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;
  }
}

Then I created this code on my form folder

 lib/form/doctrine/reservation/reservationApplicationForm.class.php
$this->validatorSchema['telephone'] = new myValidatorPhone(array(
      'required' => false,
    ));

but when I run the program I get the error:

Fatal error: Class 'myValidatorPhone' not found in C:\www\project\reservation\lib\form\doctrine\reservationApplicationForm.class.php on line 36

Based on the website this code works on 1.4 which I'm using it right now. But I don't know why I got a Fatal error.

1

1 Answers

5
votes

In your lib folder create folder validator and put into it your validator in lib/validator/myValidatorPhone.class.php