Solved

java script email validation

Posted on 2008-06-19
6
186 Views
Last Modified: 2013-11-23
I have a funcion that validates email quite nicely.. the lines:
              if (!validateEmail(document.forma.email.value)) {
           alert("La dirección de correo electrónico no es valida.");
           return false;
               }      
Do the actual validation.
What do I have to add at this level to have it return true if  the field is empty. That is either it is a vaid email or empty..
0
Comment
Question by:robrodp
6 Comments
 
LVL 17

Expert Comment

by:contactkarthi
ID: 21825884
if (document.forma.email.value="" || !validateEmail(document.forma.email.value))
0
 
LVL 17

Assisted Solution

by:contactkarthi
contactkarthi earned 100 total points
ID: 21825893
oops

if (document.forma.email.value==null || !validateEmail(document.forma.email.value))
0
 

Author Comment

by:robrodp
ID: 21826006
It is returning an error when the field is empty I need an ok validation when the field is empty or whatever is in the field passes the validemail test. I am not sure if null and "" are the same
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:robrodp
ID: 21826552
Mh.... I guess the function always returns false when the email is empty... I guess the cjage has to be done at the validation function level. The function is:

function validateEmail(fieldValue) {
     return (/^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/).test(fieldValue);
}

It returns false if the emailis empty... cant figure out why!!!
0
 
LVL 13

Assisted Solution

by:MicheleMarcon
MicheleMarcon earned 50 total points
ID: 21828730
return (fieldValue.length>0);
0
 
LVL 3

Accepted Solution

by:
sreehariharan earned 350 total points
ID: 21946340
Hi
Just Change the method as

function validateEmail(fieldValue) {
if(fieldValue !=null)
    return true;
 else
return (/^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/).test(fieldValue);
}

or u can validate away from the function also

 if (!validateEmail(document.forma.email.value)) {
if(document.forma.email.value)
{ return true;}
else
{          alert("La dirección de correo electrónico no es valida.");
           return false;
               }      

}

Just check it and let me know if there is any further issues
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 84
difference of if loops 23 49
Configure a Bean in an XML file 4 31
JavaFX TableView not displaying correctly 3 16
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now