• Very nice.

    I would make a couple of suggestions though. To avoid the loop looking at each individual character, use regular expressions to look for invalid characters:

    IF (

    @vParameter_Length = 0

    OR CHARINDEX ('@', @vParameter) < 2

    OR CHARINDEX ('.', @vParameter) < 2

    OR CHARINDEX ('.@', @vParameter) <> 0

    OR CHARINDEX ('..', @vParameter) <> 0

    OR CHARINDEX ('.', REVERSE (@vParameter)) < 3

    OR CHARINDEX ('.', @vParameter, CHARINDEX ('@',@vParameter)) = 0

    OR RIGHT (@vParameter,1) = '@'

    OR @vParameter LIKE '%@%@%'

    OR @vParameter LIKE '%[!-*]%'

    OR @vParameter LIKE '%,%'

    OR @vParameter LIKE '%/%'

    OR @vParameter LIKE '%[:-?]%'

    OR @vParameter LIKE '%[[-^]%'

    OR @vParameter LIKE '%`%'

    OR @vParameter LIKE '%[{-~]%'

    )

    Then if you are going to do it on an entire table, you can avoid the function altogether which would probably bring your SQL Server to its knees to have a function in the where clause of a select against a million row table. This query ran against an 800,000+ row table in about 4 seconds.