Advertisement

10.08.2008 at 01:58PM PDT, ID: 23799137
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

Help with email address validation checker - allow two periods but ensure text exists after last period

Asked by Bishork in JavaScript, Scripting Languages

Tags:

I am new to javascript.  I need to edit my email validation function to allow two dots but make sure that the last dot still has something after it.

The code I am working with is given below FIRST,  the second code snippet function is an email validator i found on the web.  It allows for two periods, and makes sure that there is something after the final "."  But since I'm new to js I'm having trouble understanding why it works.  

Can someone please explain to me?  Is -1 the FIRST position in the field or is 0 the first position?  Which part of the second snippet I pasted allows for two dots as well as not allowing it to pass if there is nothing after the final .

My code doesn't return "joe.joe@joe." as invalid
but the one i found on the web does.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
function checkForValidEmailAddress(emailAddressField) 
{
	var emailAddress = emailAddressField.value;
	
	// Do not throw an error if the field is blank.
	if ("" == emailAddress) 
	{
		return true;
	}
	
	var at = "@";
	var dot = ".";
	var positionOfAtSymbol = emailAddress.indexOf(at);
	var lengthOfAddress = emailAddress.length;
 
	// Check to see if an "@" character exists.
	// If it does exist, it should not be as 
	// the first or last character of the address.
	if (emailAddress.indexOf(at) == -1 
		|| emailAddress.indexOf(at) == 0 
		|| emailAddress.indexOf(at) == lengthOfAddress - 1)
	{
		emailAddressField.select();
		emailAddressField.focus();
		return false;
	}
 
	// Check to see if an "." character exists.
	// If it does exist, it should not exist as 
	// the first or last character of the address.
	if (emailAddress.indexOf(dot) == -1 
		|| emailAddress.indexOf(dot) == 0 
		|| emailAddress.indexOf(dot) == lengthOfAddress - 1 )
	{
		emailAddressField.select();
		emailAddressField.focus();
		return false;
	}
 
	// Make sure that there is a second "." character.
	if (emailAddress.indexOf(at,(positionOfAtSymbol + 1)) != -1)
	{
		emailAddressField.select();
		emailAddressField.focus();
		return false;
	}
 
	// Make sure that a "." character does not immediately
	// preceed or follow the "@" character.
	if (emailAddress.substring(positionOfAtSymbol - 1, positionOfAtSymbol) == dot 
		|| emailAddress.substring(positionOfAtSymbol + 1, positionOfAtSymbol + 2) == dot)
	{
		emailAddressField.select();
		emailAddressField.focus();
		return false;
	}
 
	// Make sure there exists at least one "." 
	// character after the "@" character.
	if (emailAddress.indexOf(dot,(positionOfAtSymbol + 2)) == -1)
	{
		emailAddressField.select();
		emailAddressField.focus();
		return false;
	}
 
	// Make sure there is no whitespace within the address.
	if (emailAddress.indexOf(" ") != -1)
	{
		emailAddressField.select();
		emailAddressField.focus();
		return false;
	}
 
	return true;				
}
 
 
<script language = "Javascript">
function echeck(str) {
 
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}
 
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}
 
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}
 
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
 
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }
 
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
 
 		 return true					
	}
 
function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
Loading Advertisement...
 
[+][-]10.08.2008 at 02:15PM PDT, ID: 22673542

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.

 
[+][-]10.08.2008 at 02:29PM PDT, ID: 22673682

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.

 
[+][-]10.08.2008 at 03:09PM PDT, ID: 22674004

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.

 
[+][-]10.08.2008 at 04:00PM PDT, ID: 22674309

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.

 
[+][-]10.10.2008 at 12:07PM PDT, ID: 22689696

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.

 
[+][-]10.10.2008 at 12:32PM PDT, ID: 22689923

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.

 
[+][-]10.10.2008 at 04:40PM PDT, ID: 22691630

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.

 
[+][-]10.11.2008 at 03:23AM PDT, ID: 22693458

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.

 
[+][-]10.11.2008 at 10:45AM PDT, ID: 22694712

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

Zones: JavaScript, Scripting Languages
Tags: javascript
Sign Up Now!
Solution Provided By: robacarp
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.13.2008 at 06:16AM PDT, ID: 22702084

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.

 
[+][-]10.13.2008 at 08:29AM PDT, ID: 22703254

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.

 
[+][-]10.13.2008 at 09:13AM PDT, ID: 22703640

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.

 
[+][-]10.13.2008 at 09:53AM PDT, ID: 22703962

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.

 
[+][-]10.13.2008 at 10:17AM PDT, ID: 22704180

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.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628