August 28, 2008 at 7:58 am
Writing an email validation code using select, where, or and like statements. Something like this:
select emailaddress from contact where ((emailaddress = ''
-This looks for entries where email was left blank
I am having trouble making the code to make sure "_" does not appear after "@". If anyone can help me out, thanks.
August 28, 2008 at 8:24 am
I'm not doing your job but here is a hint...
a = lenght of the email column.
b = position of the '@" in the email column.
If (a !< b + 4) you may have a valid email address
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.August 28, 2008 at 9:03 am
I use the following code to do some rough validation when importing email addresses.
SELECT EMail
FROM
(
    SELECT
        EMail
        ,CHARINDEX('.', REVERSE(EMail)) AS DotPos
        ,CHARINDEX('@', REVERSE(EMail)) AS AtPos
        ,CHARINDEX('@', EMail) AS AtPosStart
        ,REVERSE(LEFT(REVERSE(EMail), CHARINDEX('@', REVERSE(EMail)) - 1)) AS DomainName
        ,REVERSE(SUBSTRING(REVERSE(EMail), CHARINDEX('@', REVERSE(EMail)) + 1, 255)) AS LocalName
    FROM YourTable
) D
WHERE NOT
(
    D.DotPos > 1
    AND D.AtPosStart > 1
    AND D.AtPos > DotPos
)
    OR D.LocalName LIKE '%[^[''_=A-Z0-9-.!#$%*/?¦^{}`~&+-]%'
    OR D.DomainName LIKE '%[^[A-Z0-9-.]%'
    OR D.EMail LIKE '%..%'
    OR D.EMail LIKE '%@.%'
    OR D.EMail LIKE '%.@%'
    OR D.EMail LIKE '%:@%'
    OR D.EMail LIKE '.%'
    OR D.EMail LIKE '@%'
    OR D.EMail LIKE '%''@%'
    OR NOT EXISTS
    (
        -- This is a list of valid top and second level domains
        -- About to become useless
        SELECT *
        FROM TandSDomains TSD
        WHERE D.EMail LIKE '%' + TSD.Domain
    )
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply