I have a string which is 6 characters long (a hex code). Basically I want to have a function which returns true or false depending on if it finds a character other than 0-9 or A-F in the string.
Right now, the code that I am using looks like this:
Code: Select all
function validHex($hex) {
return preg_match_all("/ї0-9a-fA-F]/", $hex, $results) == 6;
}
This function works, but seems like a bit much to check for an invalid character. First of all, I don't need $results to be returned containing the string information. The problem is that I can't seem to figure out any other way to validate the string besides this.
I would like to just use preg_match(), so if anyone can possibly help out with this problem, it would be greatly appreciated. Thanks!