Validation in cakephp

class User extends AppModel {
var $name = ‘User’;
var $validate = array(
‘firstname’ => array(
‘rule’ => ‘/^[a-zA-Z]{0,}$/i’,
‘message’ => “Enter Firstname (Alphabets Only).”,
‘allowEmpty’=>false
),
‘lastname’ => array(
‘rule’ => ‘/^[a-zA-Z]{0,}$/i’,
‘message’ => “Enter Lastname (Alphabets Only).”,
‘allowEmpty’=>false
),

‘start_date’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Select Date of Hire.”
),
‘primary_phone_number’ => array(
‘rule’ => array(‘phone’, ‘/^\s*[0-9\-\+\s]+$/i’, ‘us’),
‘message’ => “Enter valid phone number.”,
‘allowEmpty’=>true
),
‘s_designation’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter Designation.”
),
‘p_designation’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter Designation.”
),
‘secondary_phone_number’ => array(
‘rule’ => array(‘phone’, ‘/^\s*[0-9\-\+\s]+$/i’, ‘us’),
‘message’ => “Enter valid phone number.”,
‘allowEmpty’=>true
),
‘primary_email’ => array(
‘ruleName2’ => array(
‘rule’ => array(’email’),
‘message’ => “Enter valid email address.”
),

),
‘secondary_email’ => array(
‘ruleName2’ => array(
‘rule’ => array(’email’),
‘message’ => “Enter valid email address.”,
‘allowEmpty’=>true
),

),
‘password’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter your password.”
),
‘password1’ => array(
‘loginRule-1’ => array(
‘rule’    => ‘notEmpty’,
‘message’ => ‘Enter your password.’,
),
‘rule2’ => array(
‘rule’ => array(‘minLength’, 5),
‘message’ => ‘Minimum length of 5 characters.’
),
‘rule3’ => array(
‘rule’ => array(‘maxLength’, 25),
‘message’ => ‘Maximum length of 25 characters.’
)
),

’email’ => array(
‘notEmpty’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter your email.”,
‘last’ => true
),
‘ruleName2’ => array(
‘rule’ => array(’email’),
‘message’ => “Enter valid email address.”
),

),
‘old_password’ => array(
‘ruleName’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter old password.”,
‘last’ => true
),
‘ruleName2’ => array(
‘rule’ => array(‘isOldPasswordExists’),
‘message’ => “Old password doesnot exists.”
)
),
‘confirm_password’ => array(
‘ruleName’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter confirm password.”
),
‘ruleName2’ => array(
‘rule’ => array(‘matchPasswords’,’password’),
‘message’ => “Passwords do not match.”
)
),
‘dob’ => array(
‘rule’ => array(‘validDOB’),
‘message’ => “Date of birth should not be greater than today’s date.”
)
);

and in controller
$this->Model->save($this->data, array(‘validate’=>false));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s