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
201 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

778 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