Create a User defined function to Validate EmailID in Sql Server
Create FUNCTION UDFValidateEmail (@email varChar(255))
RETURNS bit
AS
begin
return
(
select
Case
When @Email is null then 0 --NULL Email is invalid
When charindex(' ', @email) <> 0 or --Check for invalid character
charindex('/', @email) <> 0 or --Check for invalid character
charindex(':', @email) <> 0 or --Check for invalid character
charindex(';', @email) <> 0 then 0 --Check for invalid character
When len(@Email)-1 <= charindex('.', @Email) then 0--check for '%._' at end of string
When @Email like '%@%@%'or
@Email Not Like '%@%.%' then 0--Check for duplicate @ or invalid format
Else 1
END
)
end
Now call the Udf to validate Email
SELECT dbo.UDFValidateEmail('suraj@dotnetguru.in')
Valid Email returns 1 while Invalid Email returns 0 as output.
0 comments:
Post a Comment