Input Yii CMaskedTextField,一位或两位数字0-99(数量)

Input Yii CMaskedTextField,一位或两位数字0-99(数量),input,yii,Input,Yii,我试图将CMaskedTextField作为基本数量=0,最大数量=99的数量输入字段。 无法识别掩码和/或charMap 我试过: $this->widget('CMaskedTextField', array( 'model' => $position, 'attribute' => 'Quantity', 'mask' => '99', '

我试图将
CMaskedTextField
作为基本数量=0,最大数量=99的数量输入字段。 无法识别掩码和/或
charMap

我试过:

$this->widget('CMaskedTextField', array(
                'model' => $position,
                'attribute' => 'Quantity',
                'mask' => '99',
                'value' => $currentQuantity,
                'htmlOptions' => array('size' => 2, 'maxlength'=>2, 'minlength'=>1)
        ), true);
但是这个掩码意味着必须只有两个数字


可选(我想如果cmaskedtextfield不可用,js将执行此操作):当用户清除输入时,它应转换为“0”。

掩码可能通过正则表达式设置:
\d{1,2}
在模型规则()中,您可以定义:

array('attributeName', 'match', 'pattern' => '/\d{1,2}/', 
'message' => '{attribute} can only contain digits from 0 to 99'),

没有到0的转换,但为用户显示了明确的消息。

您可以在问题中发布您在view和controller/action中已经尝试过的内容吗?CMaskedTextField的mask属性在值为\d{1,2}@SergeyLobanov时工作不正常,您似乎已将
CHtml::textField
扩展为
CMaskedTextField
。真的需要吗?为什么不在正则表达式模式上使用规则验证呢?你熟悉正则表达式吗?