[charachterclass help] Matching certain characters of a string?

I have a string suppose “ABCDEF>(#*W” (could be any string)

I want a function character class, such that it returns a false value if any other character then “A-Z or a-z or 0-9 or @ or $ or [ or ] or ( or ) or . or _” exists in the string.

More explanation:
$string=“A.BC_@$09” //this should return true value, no invalid characters in it.
$string=“ABC DEF” //this should return false value (because it has space)
$string=“ABC_><” //this should return false value (because > and < characters are invalid)
$string=“ABCDEF” //this should return true value, no invalid characters in it.

Actually allowed characters are:

0-9 a-z A-Z @ $ [ ] ( ) . _

I am really weak in character classes, would be grateful if someone can get me through this.

Just curious why do you need to return true when you can just remove the characters?

Just to answer your question, see the function ctype_alnum()

because I need to return error to the user if he uses invalid symbols

Ok I have used if condition.

Thanks.

Sponsor our Newsletter | Privacy Policy | Terms of Service