title: SQL Email Verification Function using Regex
body: <p>I am trying to create a function in SQL Server 2005 to check to see if an email is in a valid format with regular expressions.</p>
  
  <p>Here is what I have so far:  </p>
  
  <pre><code>CREATE FUNCTION isValidEmailFormat
  (
      @Email varchar(100)
  )
  RETURNS bit
  AS
  BEGIN
     DECLARE @Result bit
  
     SET @Result = (SELECT CASE
                       WHEN @Email LIKE '%[a-zA-Z0-9_\-]+@([a-zA-Z0-9_\-]+\.)+  (com|org|edu|nz|au])%' 
                         THEN 1
                         ELSE 0
                    END AS Valid)
     RETURN @Result
  END
  </code></pre>
  
  <p>Am I doing something wrong with my regular expression? Or do I have to do something more to compare a varchar to a regular expression?</p>
  
  <p>-Edit-  </p>
  
  <p>Right now, whatever string I put in returns a 0, even if the email format itself is correct.</p>