asked on
alter function dbo.IsValidEmail2(@email as varchar(500))
returns tinyint
as
begin
declare @res tinyint
set @res = 0
if (
CHARINDEX(' ',LTRIM(RTRIM(@email))) = 0
AND LEFT(LTRIM(@email),1) <> '@'
AND RIGHT(RTRIM(@email),1) <> '.'
AND CHARINDEX('.',@email,CHARINDEX('@',@email)) - CHARINDEX('@',@email) > 1
AND LEN(LTRIM(RTRIM(@email))) - LEN(REPLACE(LTRIM(RTRIM(@email)),'@','')) = 1
AND CHARINDEX('.',REVERSE(LTRIM(RTRIM(@email)))) >= 3
AND (CHARINDEX('.@',@email) = 0 AND CHARINDEX('..',@email) = 0)
and @Email not like '%!%'
and @Email not like '%#%'
and @Email not like '%$%'
and @Email not like '%^%'
and @Email not like '%&%'
and @Email not like '%*%'
and @Email not like '%(%'
and @Email not like '%)%'
and @Email not like '%=%'
and @Email not like '%+%'
and @Email not like '%{%'
and @Email not like '%}%'
and @Email not like '%[%'
and @Email not like '%]%'
and @Email not like '%\%'
and @Email not like '%;%'
and @Email not like '%:%'
and @Email not like '%"%'
and @Email not like '%<%'
and @Email not like '%>%'
and @Email not like '%?%'
and @Email not like '%/%'
) set @res = 1
return @res
end