Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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