TSQL Email Validation (without regex)

后端 未结 9 744
-上瘾入骨i
-上瘾入骨i 2020-11-27 17:00

Ok, there are a million regexes out there for validating an email address, but how about some basic email validation that can be integrated into a TSQL query for Sql Server

9条回答
  •  青春惊慌失措
    2020-11-27 17:44

    Great answers! Based these recommendations I came up with a simplified function that combines the best 2 answers.

    CREATE FUNCTION [dbo].[fnIsValidEmail]
    (
        @email varchar(255)
    )   
    --Returns true if the string is a valid email address.  
    RETURNS bit  
    As  
    BEGIN
        RETURN CASE WHEN ISNULL(@email, '') <> '' AND @email LIKE '%_@%_.__%' THEN 1 ELSE 0 END
    END
    

提交回复
热议问题