title: SQL: Compare if string is MD5 hash?
body: <p>Question:</p>
  
  <p>I need to COMPARE if a string is a MD5 Hash in SQL.</p>
  
  <p>I found this PHP-function:</p>
  
  <pre><code>function isValidMd5($md5)
  {
      return !empty($md5) &amp;&amp; preg_match('/^[a-f0-9]{32}$/', $md5);
  }
  </code></pre>
  
  <p>Since SQL lacks the {32} syntax, I just duplicate [a-f0-9] 32 times:</p>
  
  <pre><code>IF '200ceb26807d6bf99fd6f4f0d1ca54d4' LIKE '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]' 
  BEGIN
      PRINT 'YES'
  END
  ELSE
  BEGIN
      PRINT 'NO'
  END 
  </code></pre>
  
  <p>However, to avoid a possible collision with a username consisting of 32 [a-f], however unlikely, I want to do the like comparison uppercase.</p>
  
  <p>But if for testing purposes I do:</p>
  
  <pre><code>IF 'E' COLLATE Latin1_General_CS_AS  LIKE ('[a-f0-9]' COLLATE Latin1_General_CS_AS )
  BEGIN
      PRINT 'yes'
  END
  ELSE
  BEGIN
      PRINT 'no'
  END 
  </code></pre>
  
  <p>I get yes, and not no. <br />
  However COLLATE Latin1_General_CS_AS should make it case-sensitive...
  <br /><br />
  How can a make the LIKE in this IF case-sensitive ?</p>