Solved

java script email validation

Posted on 2008-06-19
6
184 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
powerN  challenge 3 47
allStar challenge 1 41
Modeling a class in java 5 32
Free Alternative to JIRA 4 58
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

18 Experts available now in Live!

Get 1:1 Help Now