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
Solved

java script to validate email address and telephone

Posted on 2011-03-18
6
221 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Read about why it is more lucrative for an IT company to participate in government projects.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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