Advertisement

05.31.2008 at 09:02AM PDT, ID: 23447022
[x]
Attachment Details

sql function to check  email syntax revisited

Asked by robrodp in MS SQL Server

rickchild 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,@email) > 0)
               --If invalid character was found, return 0 to invalidate
               SET @valid = 0
            SET @invalChars = replace(@invalChars,@badChar,'')
         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,@atPos+1) > 0
         SET @valid = 0
      SET @periodPos = charindex('.',@email,@atPos)
      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.

Start Free Trial
[+][-]05.31.2008 at 09:26AM PDT, ID: 21684185

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.31.2008 at 10:30AM PDT, ID: 21684379

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.01.2008 at 12:46PM PDT, ID: 21688208

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 01:29AM PDT, ID: 21690333

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:20AM PDT, ID: 21690999

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:33AM PDT, ID: 21691056

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:40AM PDT, ID: 21691089

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:46AM PDT, ID: 21691117

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:48AM PDT, ID: 21691132

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:56AM PDT, ID: 21691176

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:58AM PDT, ID: 21691187

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:59AM PDT, ID: 21691193

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 05:25AM PDT, ID: 21691312

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 05:37AM PDT, ID: 21691387

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 05:52AM PDT, ID: 21691488

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 06:01AM PDT, ID: 21691538

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 06:08AM PDT, ID: 21691584

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 06:18AM PDT, ID: 21691654

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 06:47AM PDT, ID: 21691894

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 06:59AM PDT, ID: 21692004

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: f_o_o_k_y
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628