Domanda

I want to to set validation rule in model for user enter only special character only into text field .so please suggest me proper solution.

demo code is

public function addValidations()
    {
        parent::addValidations();
        $this->validate['Field name'] = array
        (
            'notempty' => array
            (
                'rule'    => array('special char', 'msg',),
                'allowEmpty' => false,
                'message' => 'Enter Special character only.',
            ),
        );
    }
È stato utile?

Soluzione

you can define Custom Regular Expression Validation

public $validate = array(
    'login' => array(
        'rule'    => '/^[\W]+$/',
        'allowEmpty' => false,
        'message' => 'Enter Special character only.'
    )
)
// '/^[\w.-]+$/' this will allow only special character.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top