• --I don't know the full rules, but here's some simple SQL code
    --which does at least some of it.
    --It could be used in a where clause or case statement,
    --inside a function or not.
    --More conditions can easily be added along similar lines,
    --so this ought to be able to do what you want with some tweaking.
    --
    --This allows any number of dots, and one @.
    --One of the dots must be after the @.
    --
    --For all dots, and the @:
    --none of these may be at the beginning or end of the string,
    --and no two may be adjacent.
    --
    --All other characters must be alphanumeric or _ or -
     

    declare

    @vc table(vc varchar(50))

    insert

    @vc

    select

    'dhskjdhfkss' union all

    select

    'dhsk@fkss' union all

    select 'dhsk@fkss.' union all

    select ';dhsk@fkss.ooo' union all

    select

    'dh-sk@fk-ss.ooo' union all

    select

    'dh\sk@fk-ss.ooo' union all

    select

    '@fkss.das' union all

    select

    'dhsk@fkss.a.asd.asd.aaaaaa' union all

    select

    'dhsk@fkss.ddd..dddd' union all

    select

    'dh+k@fkss.ddd.d' union all

    select

    'dhsk@fkss.ddd.kk.dd' union all

    select

    'dhsk@f#ss.ddd' union all

    select

    'd--k@f_ss.ddd' union all

    select

    '------@__-ss.___._._._' union all

    select

    'dhsk@f#ss.ddd' union all

    select

    'dh_k@fkss.ddd' union all

    select

    'dhsk@fkss.' union all

    select

    '.dhsk@fkss.nnn' union all

    select

    'sgsgaha.sksjkajd.d.d.dhsk@fkss.nnn.dsdsd.as' union all

    select

    'd.h.s.k@f.k.s.s.f' union all

    select

    'd@f.s' union all

    select

    'd.hs@fkss.d' union all

    select

    'd.sk.@ggg.fkss.ddd'

    --

    select

    vc.vc VALID____________________________

    from

    @vc vc

    where

    not vc.vc like '%[^a-Z0-9.@!_-]%' escape '!' --contains only alphanumeric, '-', '.' and '@'

    and

    not vc.vc like '%@%@%' --has no more than one '@' sign

    and

    not vc.vc like '%..%' --no adjacent dots

    and

    not vc.vc like '.%' --no leading dot

    and not vc.vc like '%.' --no trailing dot

    and vc.vc like '%[^.]@[^.]%._%' --has an '@' without dots next to it, and to its right a dot followed by another char.

    --

    select

    vc.vc INVALID__________________________

    from

    @vc vc

    where

    vc.vc like '%[^a-Z0-9.@!_-]%' escape '!' --contains only alphanumeric, '-', '.' and '@'

    or

    vc.vc like '%@%@%' --has no more than one '@' sign

    or

    vc.vc like '%..%' --no adjacent dots)

    or

    vc.vc like '.%' --no leading dot

    or vc.vc like '%.' --no trailing dot

    or

    not vc.vc like '%[^.]@[^.]%._%' --has an '@' without dots next to it, and a dot afterwards.

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant