Notice: Undefined offset: 8192 in /home/miphpf/domains/miphpf.com/public_html/includes/common.inc on line 499

Notice: Undefined offset: 8192 in /home/miphpf/domains/miphpf.com/public_html/includes/common.inc on line 506

Warning: Incorrect key file for table './miphpf_miphpfcom/watchdog.MYI'; try to repair it query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/miphpf/domains/miphpf.com/public_html/includes/unicode.inc on line 291.', 2, '', 'http://www.miphpf.com/manual/validators.html', '', '3.238.112.198', 1716793106) in /home/miphpf/domains/miphpf.com/public_html/includes/database.mysql.inc on line 121
Validators | MIPHPF - Your Open Source RAD PHP Framework
Skip navigation.
Home

Validators

: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/miphpf/domains/miphpf.com/public_html/includes/unicode.inc on line 291.

Validators objects perform sanity checks on the user input. Validators can be added to a web form statically (mapped in the data manager class) or at runtime.

The following validators are built-in the framework:
* miValidatorDate - checks if the data is a valid date string
* miValidatorDecimal - ensures that data is valid decimal number
* miValidatorEmail - check if the data is valid e-mail address
* miValidatorGsm - checks if the data is valid mobile phone number
* miValidatorHttp - ensures that the data is valid www location
* miValidatorIcq - checks if the data is valid ICQ number
* miValidatorInt - ensures that data is integer
* miValidatorIp - ensures that data is an computer IP (IPv4)
* miValidatorUnique - ensures that the value is unique in the database column

For text fields 'minLength' and 'maxLength' properties are available to check if field data is the correct length.
* Map validators

<?php
class miUserDataManager extends miDataManager
{
   
protected $_dataFields = array(
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserEmail',
           
'validator' => array('miValidatorEmail')
        )
    );
}
?>

* Create validators runtime
<?php
class miUserDataManager extends miDataManager
{
   
protected $_dataFields = array(
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserLoginName'
       
),
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserICQ'
       
)
    );

   
public function initWebForm(miWebForm $form)
    {
       
parent::initWebForm($form);

       
$record = new miSqlRecord('Users', 'UserID');

       
// Unique validator can be created only at runtime because requires additional parameters
       
$loginFieldValidator = new miValidatorUnique($form, 'UserLoginName', $record);
       
$form->addValidator('UserLoginName', $loginFieldValidator);

       
$icqFieldValidator = new miValidatorIcq($form, 'UserICQ');
       
$form->addValidator('UserICQ', $icqFieldValidator);
    }
}
?>

* Usage of minLength and maxLength properties
<?php
// In this example the 'UserPassword' field allows passwords from 4 to 32 characters (inclusive)
class miUserDataManager extends miDataManager
{
   
protected $_dataFields = array(
        array(
           
'field' => 'miWebFormWidgetText',
           
'data' => 'UserPassword',
           
'properties' => array('minLength' => 4, 'maxLength' => 32)
        )
    );
}
?>