Posted By

duniyadnd on 02/11/09


Tagged

php hex regular Expression hexadecimal reg exp


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


preg_match for Hexadecimal Strings


 / Published in: PHP
 

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.

  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  

You need to login to post a comment.