正则表达式验证表单

I can not figure out how can I put 5 characters that has a-z, A-Z, 0-9, and can include $ and @ with regex. This is what I have

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

it keeps showing error.

Use positive lookaheads:

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

Explaining:

^                     # 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

Hope it helps.