Solved

java script to validate email address and telephone

Posted on 2011-03-18
6
218 Views
Last Modified: 2012-05-11
I am looking for an example of some java script to validate a user entered a telephone number and a email address correctly anyone got any good examples or sites with code I can check
0
Comment
Question by:enigma1234567890
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35165777
check this for email validation
http://www.roseindia.net/ajax/jquery/validate-email-address.shtml

what is the format of telephone number you are looking for?
0
 

Author Comment

by:enigma1234567890
ID: 35167192
this is too many different techonologies I want java Script
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35167238
that is javascript only, let me make it simpler for you

var str = "sadasd@asd.dfd";
var myArray = str.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/g)

if ( myArray != null)
{
alert("valid email");
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:enigma1234567890
ID: 35167365
what i really nned to know is if i have this code how do i convert it to do regex expressions

if (document.x.email.value ==""){
alert("Please enter email address");
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35167407
function isvalidEMail(emailStr)
{
   var myArray = emailStr.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/g);

    if ( myArray != null)
    {
          return true;
    }
    return false;  
}


var emailStr = document.x.email.value;
if ( emailStr =="" && !isvalidEMail(emailStr)){
alert("Please enter email address");

0
 
LVL 7

Accepted Solution

by:
foobarr earned 500 total points
ID: 35183310
 function ValidateEmailAddress(eAddy) {
            var pattern;

            pattern = /^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,10})$/;

            try {
                if (eAddy == "") {
                    return false;
                }
                else {

                    return pattern.test(eAddy);

                }
            }
            catch (e) {
                 alert("error:" + e);
            }
        }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
With the rapid rise in mobile usage, mobile devices are here to stay and have become an integral part of doing business. Here are 9 great apps for your BYOD environment.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

13 Experts available now in Live!

Get 1:1 Help Now