If I understand your question right, the solution is quite easy. I will use preg_match, but you could easily use ereg or eregi.
if(preg_match('/[^\w@.]/i', $haystack)) {
// haystack contains invalid characters.
}
else{
// haystack contains no invalid characters.
}
The part of the pattern '/[\w@.]/i' that actually does the work is this part: [\w@.]
I'm sure you know about the [...] syntax meaning a character class so it will match any single character that is specified in the square brackets.
If the character class begins with a caret character, then it becomes a negated character class. For example, the character class [a-z] will match any character from 'a' to 'z.' By adding the caret character to the start, we have [a-z] and this will match any character that is not from 'a' to 'z.'
So, in your case, you just have to type all the characters that are valid in square brackets, and just put a caret character at the start of the square brackets. That will match any characters but the ones you specify.
Does that answer your question?