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
206 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 250 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 250 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

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!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

630 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