Solved

I sea a  javascript funtion to validate emails... I need it to pass when the email field is empty

Posted on 2008-06-19
6
199 Views
Last Modified: 2013-11-23
The function always returns false when the email is empty... I guess a change 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
Comment
Question by:robrodp
6 Comments
 
LVL 10

Accepted Solution

by:
krishna kishore mellacheruvu venkata earned 250 total points
Comment Utility
Try this code

 function validateEmail(fieldValue) {
      if (fieldValue!=null && fieldValue.length > 0)
      {
      
     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);
       }
       return true;
}
0
 
LVL 6

Assisted Solution

by:manuel_m
manuel_m earned 250 total points
Comment Utility
You can check for null and for undefined. It's only an extension of the code from melchkishore :-)

manuel
function validateEmail(fieldValue) {

      if ((fieldValue != null || typeof(fieldValue) == "undefined") && fieldValue.length > 0)

      {

      

     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);

       }

       return true;

}

Open in new window

0
 
LVL 9

Expert Comment

by:mbodewes
Comment Utility
Notice that you post this in the "new to java" zone. This is a JavaScript question and should really be posted in the zone with the same name. JavaScript != Java.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:robrodp
Comment Utility
Mh... I am relly new right?

Thanks
0
 
LVL 10

Expert Comment

by:krishna kishore mellacheruvu venkata
Comment Utility
Did your problem got solved?
0
 

Author Comment

by:robrodp
Comment Utility
Yes... I am sending the Accept as solution right now
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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.

771 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

16 Experts available now in Live!

Get 1:1 Help Now