I need to use in my form just positive numbers so I used numberPattern’=>’^[+]?\d+([.]\d+)?$’ but not worked .
this is my Model :
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('count,user_id', 'required','message'=>'يرجى ملئ حقل {attribute} '),
array('count, user_id', 'numerical','numberPattern'=>'^[+]?\d+([.]\d+)?$', 'integerOnly'=>true,'message'=>'Error '),
array('count', 'length','max'=>5 ,'min'=>1,'tooShort'=>'عدد الأحرف أقل من {min} '),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('st_id, count, price, b_date, user_id', 'safe', 'on'=>'search'),
);
}
I’m not sure why you’re using a regex which matches decimals when you’re specifying that only integers should be accepted though. If you’re intending to match decimal values, you should remove ‘integerOnly’=>true .
array('count', 'length', 'min' => 1, 'max'=>5,
'tooShort'=>Yii::t("translation", "{attribute} is too short."),
'tooLong'=>Yii::t("translation", "{attribute} is to long.")),
array('count', 'match', 'pattern'=>'/^[0-9]+$/'),