我正在尝试使用yii2中的Regex验证程序验证以下电话号码:
+6018-2031218
0060182031218
006018-2031218
像这样
public function rules()
{
return [
[['name', 'minimum_order_amount', 'time_order_open', 'time_order_close', 'delivery_fee', 'rank', 'halal', 'featured', 'working_opening_hours', 'working_closing_hours', 'disable_ordering', 'delivery_duration', 'phone_number', 'longitude', 'latitude', 'image', 'status', 'owner_id', 'user_id'], 'required'],
[['minimum_order_amount', 'delivery_fee', 'rank', 'longitude', 'latitude'], 'number'],
[['time_order_open', 'time_order_close', 'working_opening_hours', 'working_closing_hours', 'created_at', 'updated_at'], 'safe'],
[['halal', 'featured', 'disable_ordering', 'delivery_duration', 'status', 'owner_id', 'user_id'], 'integer'],
[['name', 'phone_number', 'image'], 'string', 'max' => 255],
[['working_opening_hours','working_closing_hours','time_order_open', 'time_order_close'], 'date', 'format' => 'H:m:s'],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
[['owner_id'], 'exist', 'skipOnError' => true, 'targetClass' => Owners::className(), 'targetAttribute' => ['owner_id' => 'id']],
[['phone_number'], 'match', 'pattern' => '/((\+[0-9]{6})|0)[-]?[0-9]{7}/'],
];
}
但我无法获得正确的正则表达式,因为那些手机号码是否有任何不同的方式可以在yii2中执行此操作。
答案 0 :(得分:0)