php - Minimum and Maximum rule for words? -
in yii
there rule
should define min , max number of words in textfield
i used
array('text', 'length', 'min'=>5, 'max'=>40000),
but charecters
need min 4 words , max 4000 words instead of character
you can make custom rule validate word length on yii side, considering text area name description.
public function rules() { return array( array('description', 'validatewordlength'), ); }
now thing need create new method inside model, named after validation rule declared.
public function validatewordlength($attribute,$params) { $total_words= str_word_count($object->$attribute); if($total_words>4000) { $this->adderror($attribute, 'your description length exceeded'); } if($total_words<5) { $this->adderror($attribute, 'your description length small'); } }
Comments
Post a Comment