Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
209 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 1000 total points
ID: 21828638
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 1000 total points
ID: 21828893
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
ID: 21903905
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:robrodp
ID: 21903929
Mh... I am relly new right?

Thanks
0
 
LVL 10
ID: 21905492
Did your problem got solved?
0
 

Author Comment

by:robrodp
ID: 21907180
Yes... I am sending the Accept as solution right now
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

876 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