我有一个名为imsi
的列string
,我想只在其中添加数字,所以我使用了
[['imsi'], 'match','pattern'=> '[0-9]','message'=>'IMSI must include only numbers'],
现在,当我尝试创建新记录并插入带有或不带数字的imsi
号码时,它总会给我错误信息。
我的模特是
public function rules()
{
return [
[['imsi','operator_name','data_details','sms_details','status'], 'required'],
[['created_by', 'updated_by', 'sim_stauts', 'issued_to', 'returned_by', 'historic','data_details'
,'sms_details','monthly_bill','bill_date','credit_limit'], 'integer'],
[['created_at', 'updated_at','returned_at'], 'safe'],
[['imsi'], 'match','pattern'=> '[0-9]','message'=>'IMSI must include only numbers'],
[['operator_name'], 'string', 'max' => 20],
[['sim_number', 'status','plan_name','imsi'], 'string', 'max' => 50],
//[['monthly_bill'], 'string', 'max' => 100],
//[['imsi'], 'unique'],
[['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['created_by' => 'id']],
];
}
我如何完全匹配模式?
任何帮助都将受到高度赞赏。
答案 0 :(得分:1)
您的模式无效(您缺少分隔符),也只匹配单个数字,添加+
以标记您要允许多个数字
尝试
[['imsi'], 'match','pattern'=> '/^[0-9]+$/','message'=>'IMSI must include only numbers'],