preg_match for Hexadecimal Strings


/ Published in: PHP
Save to your folder(s)

Figure out if the string possesses only hexadecimal characters in the string. If not, fail. Remember, white spaces are not hexadecimal, so make sure you trim() your strings before you send it in or explode your string.


Copy this code and paste it in your HTML
  1. function isHexadecimalString ( $str ) {
  2. if ( preg_match("/^[a-f0-9]{1,}$/is", $str) ) {
  3. return true;
  4. } else {
  5. return false;
  6. }
  7. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.