re: Validate email address

Posted on 2006-05-23
Last Modified: 2012-05-05
Hi all!

I have the following form, and would like to validate the phone and email address before it's submitted - so the email addresses are the same in both entries, etc.  I've tried a few tricks, but can't get it working. Any tips?

Thanks in advance


<form name="form" method="post" action="http://www.narcissusdesign/cgi-bin/cgiemail/email.txt">
              <table width="100%" border="0" cellpadding="2" cellspacing="2" class="fonts">
                  <td width="23%">Firstname:</td>
                  <td width="77%"><input name="firstname" value=" " type="text" size="45"></td>
                  <td><input name="lastname" value=" " type="text" size="45"></td>
                  <td><input name="email" value=" " type="text" size="45"></td>
                  <td>Verify Email:</td>
                  <td><input name="verifyemail" type="text" id="verifyemail" value=" " size="45"></td>
                  <td>Phone Number:</td>
                  <td><input name="phone" value=" " type="text" size="45"></td>
                  <td>Verify Phone Number:</td>
                  <td><input name="verifyphone" type="text" id="verifyphone" size="45"></td>
                  <td>Preferred Contact Mode:</td>
                  <td><input name="preferemail" type="checkbox" id="preferemail" value="checkbox">
                    <input name="preferphone"type="checkbox" id="preferphone" value="checkbox">
                    Phone </td>
                  <td><input name="subject" type="text" id="subject" size="45"></td>
                  <td align="left" valign="top">Question/Comment:</td>
                  <td><textarea name="comment" value="comment" cols="50" rows="10"></textarea></td>
                  <td><br> <input type="reset" name="reset" value="Reset Form">
                    &nbsp;&nbsp; <input type="submit" name="submit" value="Submit Email">
                    <br> <INPUT TYPE="hidden" NAME="addendum" VALUE="">
Question by:angmine
    1 Comment
    LVL 12

    Accepted Solution

    Hi angmine,

    Here's a simple example for ensuring that both the phone and the verifyphone text fields are the same:

    <FORM onSubmit="return validate(this)">
    <INPUT TYPE="text" id="phone"><br>
    <INPUT TYPE="text" id="verifyphone"><Br>
    <INPUT TYPE="submit">

    <script language="JavaScript" type="text/javascript">
    function validate(Form) {
        if ( != Form.verifyphone.value)
            alert("phones not identical");
            return false;

    - Maddog

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now