允许使用Regex进行单引号、双引号和句号


Allow single ,double quote and full stop with Regex

我已经用cake php模型实现了验证,只允许使用字母。下面是代码

'referer' => array(
    'notempty3' => array(
        'rule'      => '/^[a-zA-Z's]+$/',
        'message' => 'Only letters allowed.',
        'allowEmpty' => false,
        'required' => true,
        //'last' => false, // Stop validation after this rule
        //'on' => 'create', // Limit validation to 'create' or 'update' operations
    )
)

但我想加上允许单引号、双引号和字母句号。

然后将正则表达式更改为:

/^[a-zA-Z's'".]+$/

您只需要将它们添加到角色类中即可。