Solved

java script to validate email address and telephone

Posted on 2011-03-18
6
225 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
[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
  • 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
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.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Part Two of the two-part Q&A series with MalwareTech.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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