正则表达式验证窗体


Regular expression validate form

我不知道如何用正则表达式放置具有a-zA-Z0-9并且可以包括$@的5个字符。这就是我的

$char_regex = '/^[a-zA-Z0-9@'$]{5}$/';

它不断显示错误。

使用正向外观

$char_regex = '/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9@'$]{5}$/';

解释:

^                     # from start
(?=.*[a-z])           # means should exist one [a-z] character in some place
(?=.*[A-Z])           # same to upper case letters
(?=.*[0-9])           # same to digits
[a-zA-Z0-9@'$]{5}$    # your current regex

希望能有所帮助。