Norman
Norman

Reputation: 6365

Regular expression to detect few non characters

How do i do a regular expression that will allow everything except !@$%^&*()_+={}[]|:";'<>,.?/ (If i need to detect more than these can I simply add them into the regexp later?)

I intend using this to check if these character are present in postal addresses a user submits. So if they were there, I could reject the address.

Thanks

Upvotes: 0

Views: 156

Answers (1)

Colin Hebert
Colin Hebert

Reputation: 93157

You should include allowed characters instead of excluding almost everything :

[\w+-]*

But if you want to really exclude those chars :

[^!@$%^&*()_+={}\[\]|\:";'<>,.?/]*

Resources :

Upvotes: 2

Related Questions