This little snippet is used to validate that the input only has the characters you desire.  In this example it allows for uppercase A-Z, lowercase a-z, Numbers 0-9, and special characters . _ and -

You can modify this by removing any of the characters you don't want to check for. {codecitation}
$data = "a_sdf.-A999";

if(preg_match('/^[a-zA-Z0-9._-]*$/',$data)){
    echo 'only contains valid characters';
} else {
    echo 'contains invalid characters';
}{/codecitation}The above example results in 'only contains valid characters.

Note:  If you are using this for validation you may want to check the strings length also to verify that data was entered otherwise a blank string would validate. The above code could be modified to enforce a minimum string length of 7.{codecitation}$data = "a_sdf.-A999";

if(preg_match('/^[a-zA-Z0-9._-]*$/',$data) && strlen($data)>=7){
    echo 'only contains valid characters';
} else {
    echo 'contains invalid characters';
}{/codecitation}