Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All Topicsrickchild provided this function to check email syntax
CREATE FUNCTION EMAILVALIDATE (@email varChar(100))
RETURNS int
AS
BEGIN
DECLARE @invalChars varchar(5),@valid int,@badChar varchar(1),@atPos
int,@periodPos int
SET @valid = 1
SET @invalChars = ' /:,;'
--Check to see if it's blank
IF len(ltrim(rtrim(@email))) = 0
SET @valid = 0
ELSE
--Loop invalid characters to see if it exists in email
WHILE len(@invalChars) > 0
BEGIN
SET @badChar = substring(@invalChars,1,1)
IF(charindex(@badChar,@ema
--If invalid character was found, return 0 to invalidate
SET @valid = 0
SET @invalChars = replace(@invalChars,@badCh
END
--Check to see if "@" exists.
SET @atPos = charindex('@',@email,1)
IF @atPos = 0
SET @valid = 0
--Check to see if extra "@" exists after 1st "@".
IF charindex('@',@email,@atPo
SET @valid = 0
SET @periodPos = charindex('.',@email,@atPo
IF @periodPos = 0
SET @valid = 0
IF (@periodPos+3) > len(@email)
SET @valid = 0
RETURN (@valid)
END
It works but has 2 glitches
1. at the beginning it cehck for invalid characters and has a list ' /:,;'
It checks for these characters... but if á or ñ are in the email it give an ok answer. ideal to have a translation table or just report it as invalid.
Why not test for valid characters (the list is shorter than the possible invalid characters) of course you have to check all charactes where as when checkin for invalid characters as soon as you find one it is automatically invalid.
Other considerations_ the '_' is valid for the user part but not the domain and the '-' is valid for the domain but not the user
2. Towards the end it checks for a '.' to check for .com .net.org etc. it uses a 3 as parameter to all addresses with .mx .cl .co etc are reportes as invaled. I changed the 3 to a 2 and it seems to work...
A solution to the first part woul be welcome.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: f_o_o_k_yPosted on 2008-05-31 at 09:26:03ID: 21684185
Comments are available to members only. Sign up or Log in to view these comments.