Source for file Validators.php
Documentation is available at Validators.php
* Web form validator classes
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
* The base validator class
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
* Constructs the validator class
* @param miWebForm $webForm
* @param string $fieldName
public function __construct(miWebForm &$webForm, $fieldName)
* Retrieve the field name
* @return string the field name
* @param string $fieldName the field name
* @param miWebFormErrorsHandler
public function validate(miWebFormErrorsHandler &$errors)
* Validates email set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
if (preg_match('/^[A-Za-z0-9]+([_\.-A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/iU', $fieldValue))
$errors->addError($this->_fieldName, 'Invalid email format');
* Validates date set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
if (preg_match('#^\d{4}-\d{2}-\d{2}$#', $fieldValue)) {
$pieces =
explode("-", $fieldValue);
if (checkdate($pieces[1], $pieces[2], $pieces[0]))
$errors->addError($this->_fieldName, 'Invalid date format');
* Validates integer set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
$errors->addError($this->_fieldName, 'Invalid integer');
* Validates decimal set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
if (preg_match('#^[0-9]{1,10}\.?([0-9]){0,2}$#', $fieldValue))
$errors->addError($this->_fieldName, 'Invalid decimal');
* Validates ICQ set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
if ($fieldValue >
10000 and $fieldValue <
2147483646)
$errors->addError($this->_fieldName, 'Invalid ICQ');
* Validates http url set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
if (substr($fieldValue, 0, 7) ==
'http://')
$errors->addError($this->_fieldName, 'Invalid http url');
* Validates GSM set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
$errors->addError($this->_fieldName, 'Invalid GSM');
* Validates IP address set by user
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
public function validate(miWebFormErrorsHandler &$errors)
$errors->addError($this->_fieldName, 'Invalid IP address');
* Makes sure that the field value is unqiue.
* There is a special allowence that if the value is already in the database it is allowed even if duplicate
* @copyright Copyright (c) 2006 Mirchev Ideas Ltd. All rights reserved.
* The actual record used to read the data
* Constructs the unique validator class
* @param miWebForm $webForm
* @param string $fieldName
* @param miSqlRecord $record
public function __construct(miWebForm &$webForm, $fieldName, miSqlRecord $record)
public function validate(miWebFormErrorsHandler &$errors)
// In case such record already exists, i.e. editing
// If there is no change, do not bother validating
if ($fieldValue ==
$oldValue)
// Check if there is another record with the value
$checkRecord->read($this->_fieldName, $fieldValue);
// Record doesn't exists. The value is unqiue
if ($exception->getCode() ==
miDBException::EXCEPTION_RECORD_NOT_FOUND)
// OOps, different exception. Rethrow
// The value is not unique
$errors->addError($this->_fieldName, 'Not unique');
Documentation generated on Thu, 08 May 2008 16:57:53 +0300 by phpDocumentor 1.4.1