Kohana验证正则表达式-必须有上下字符


Kohana Validation Regex - Must have lower and upper character

我使用以下正则表达式

->rule('password','regex', array(':value', "(?=.*?[a-z])(?=.*?[A-Z])"))

但是Kohana抱怨'('是一个Unknown修饰语。是否有另一种方法来正则字符串,以确保它有1个或多个小写字母和1个或多个大写字母?

PHP期望在其正则表达式周围附加分隔符(并且将第一组括号误认为是分隔符)。使用

->rule('password','regex', array(':value', "/(?=.*?[a-z])(?=.*?[A-Z])/"))

也许锚定到字符串的开头。这样,如果regex失败,将只测试一次,而不是对字符串中的每个字符都测试一次:

->rule('password','regex', array(':value', "/^(?=.*?[a-z])(?=.*?[A-Z])/"))

~([a-z].*[A-Z]|[A-Z].*[a-z])~

?

看到http://kohanaframework.org/3.0/guide/api/Validate regex