脚本宝典收集整理的这篇文章主要介绍了如何在PHP中“合并”这两个正则表达式?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如果不以_(下划线)开头且仅包含单词字符(字母,数字和下划线本身),则用户名被视为有效:
namespace Gremo\ExtraValidationBundle\Validator\Constraints; use Symfony\component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; class UsernameValidator extends ConstraintValidator { public function validate($value,Constraint $constraint) { // Violation if username starts wITh underscore if (PReg_match('/^_',$value,$matches)) { $this->context->addViolation($constraint->message); return; } // Violation if username does not contain all word characters if (!preg_match('/^\w+$/',$matches)) { $this->context->addViolation($constraint->message); } } }
^_+[^\w]+$
要读作:如果以下划线(最终多于一个)开头并且如果不允许至少一个字符(不是字母,数字或下划线),则添加违规.例如,不适用于“_test”.
你能帮我理解我错在哪里吗?
以上是脚本宝典为你收集整理的如何在PHP中“合并”这两个正则表达式?全部内容,希望文章能够帮你解决如何在PHP中“合并”这两个正则表达式?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。