?
Solved

Validate if the data typed in the textbox is a valid e-mail address

Posted on 2003-03-12
4
Medium Priority
?
192 Views
Last Modified: 2010-03-31
Im currently constructing a e-mail like JavaScript Program.
It has a FirstName, LastName, Phone and e-mail address TextBox.

==========================================================================
<script language="Javascript">
function echeck(str) {

          var at="@"
          var dot="."
          var lat=str.indexOf(at)
          var lstr=str.length
          var ldot=str.indexOf(dot)
          if (str.indexOf(at)==-1){
             alert("Invalid E-mail ID")
             return false
          }

          if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
             alert("Invalid E-mail ID")
             return false
          }

          if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
              alert("Invalid E-mail ID")
              return false
          }

           if (str.indexOf(at,(lat+1))!=-1){
              alert("Invalid E-mail ID")
              return false
           }

           if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
              alert("Invalid E-mail ID")
              return false
           }

           if (str.indexOf(dot,(lat+2))==-1){
              alert("Invalid E-mail ID")
              return false
           }
         
           if (str.indexOf(" ")!=-1){
              alert("Invalid E-mail ID")
              return false
           }

            return true                        
     }

function ValidateForm(){
     var emailID=document.frmSample.txtEmail
     var fname=document.frmSample.fn
     var lname=document.frmSample.ln
     var pno=document.frmSample.pn
     
     if ((fname.value==null)||(fname.value=="")){
          alert("Please Enter your Firstname")
          fname.focus()
          return false
     }
     if ((lname.value==null)||(lname.value=="")){
          alert("Please Enter your Lastname")
          lname.focus()
          return false
     }
     if ((pno.value==null)||(pno.value=="")){
          alert("Please Enter your Phone NUmber")
          pno.focus()
          return false
     }
     if ((emailID.value==null)||(emailID.value=="")){
          alert("Please Enter your Email ID." + "Example you@yahoo.com")
          emailID.focus()
          return false
     }
     if (echeck(emailID.value)==false){
          emailID.value=""
          emailID.focus()
          return false
     }
     return true
 }
</script>
============================================================================

What I want is that after i put my e-mail add and i click submit, first it will verify the first character if it has an underscore character if not it must automatically put an underscore. also in phone number the dash character is automatically with the number example (047-222-2222).
0
Comment
Question by:codebreaker
[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
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
glottis earned 750 total points
ID: 8118000
1. you want to add underscore at the begining of the email:

in the echeck function before the line:
  var at="@"
insert this:
  if (str.charAt(0) != '_') {
    str = "_" + str;
  }

this will see if there is a underscore at the first charachter, if not then add one to it.

2. you want to add dashes in the phone:
if the phone is valid. ie 0471231234 then you coud do is:
pno.value = pno.value.substring(0, 3) + "-" + pno.value.substring(3, 3) + "-" + pno.value.substring(6)

hope this is what you want and helps :)
0
 
LVL 92

Expert Comment

by:objects
ID: 8122936
u should ask this question in javascript topic.
0
 

Expert Comment

by:CleanupPing
ID: 9058754
codebreaker:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 2

Expert Comment

by:glottis
ID: 9067808
i did help... even in though it was in wrong TA.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 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