Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SamC
White Water Yakist
3467 Posts |
Posted - 2002-09-03 : 18:56:14
|
For what it's worth, here are 3 procedures I wrote which helped me with the qualification and ordering of existing email lists.The EmailDomain and EmailPrefix functions are pretty neat to order selected results:Select Email from Mytable ORDER BY dbo.EmailDomain(Email), dbo.EmailPrefix(Email)Finding invalid emails is easy withSELECT Email from MyTable WHERE dbo.EmailIsValid(Email)=0Any comments on improvements would be appreciated.SamCCREATE FUNCTION dbo.EmailIsValid (@Email varchar (100))RETURNS BITASBEGINDECLARE @atpos int, @dotpos intSET @Email = LTRIM(RTRIM(@Email)) -- remove leading and trailing blanksIF LEN(@Email) = 0 RETURN(0) -- nothing to validateSET @atpos = charindex('@',@Email) -- position of first (hopefully only) @IF @atpos <= 1 OR @atpos = LEN(@Email) RETURN(0) -- @ is neither 1st or last or missingIF CHARINDEX('@', @email, @atpos+1) > 0 RETURN(0) -- Two @s are illegalIF CHARINDEX(' ',@Email) > 0 RETURN(0) -- Embedded blanks are illegalSET @dotpos = CHARINDEX('.',REVERSE(@Email)) -- location (from rear) of last dotIF (@dotpos < 3) or (@dotpos > 4) or (LEN(@Email) - @dotpos) < @atpos RETURN (0) -- dot / 2 or 3 char, after @RETURN(1) -- Whew !!ENDGoCREATE FUNCTION dbo.EmailDomain (@Email varchar (100))RETURNS varchar (100)ASBEGIN RETURN (SUBSTRING(@Email, charindex('@', @Email+'@')+1, LEN(@Email)))ENDGoCREATE FUNCTION dbo.EmailPrefix (@Email varchar (100))RETURNS varchar (100)ASBEGIN RETURN (LEFT(@Email, charindex('@', @Email+'@')-1))ENDGo |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2002-09-06 : 22:41:18
|
I have written an email validation component which validates email on three levels.1) Syntax2) Domain validity check3) SMTP validationThe proc uses a COM component available from Hexillion.comand call it from SQL using sp_oacreate. If you are interested in something like this check out http://www.hexillion.com/software/components/HexValidEmail/ |
|
|
|
|
|
|
|