2015-11-25 158 views
0

我想不通我怎麼可以把具有a-zA-Z0-9 5個字符,可以包括$@用正則表達式。這是我的正則表達式驗證表單

$char_regex = '/^[[email protected]\$]{5}$/'; 

它一直顯示錯誤。

+2

請爲您的表單提供正確和錯誤輸入的示例。 – Rulisp

+1

正則表達式適合我。請提供[MCVE],以便我們重現您的問題 – Rizier123

回答

1

使用積極向前看符號

$char_regex = '/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[[email protected]\$]{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 
[[email protected]\$]{5}$ # your current regex 

希望它能幫助。