如何唯一验证两个值,其中一个在 yii2 中有标点符号?

How to unique validation two value that one of them has punctuations in yii2?

在我的表单中,我有一个 textfield 已设置为 jquery-masked-input,这是 jquery 脚本:

<script>
jQuery(function ($) {
    $("#reg-number").mask("99.999.999.9-999.999");
});
</script>

然后,该值将不带 标点符号 保存到数据库中。所以当我输入这样的值时:

将像这样保存在 mysSQL 数据库中:

但我需要将此字段设置为唯一。 所以我在 model.php:

中添加了这个验证
public function rules()
{
    return [
        [['regNumber'], 'required'],
        [['regNumber'], 'string', 'max' => 32, 'min' => 15],
    ];
}

但它没有用,我猜是因为来自 textfield 的值包含标点符号,而在数据库列中不包含标点符号。

我怎样才能让它发挥作用?

谢谢

尝试使用 Filter validator.

['regNumber', 'filter', 'skipOnArray' => true, 'filter' => function ($value) {
   return preg_replace("/[^a-zA-Z 0-9]+/", "", $value);
}],
[['regNumber'], 'string', 'max' => 32, 'min' => 15],
[['regNumber'], 'unique'],

虽然没有测试:)