Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7950701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:21:14+00:00 2026-06-04T02:21:14+00:00

Working on a validation script for a clients site. Each function works correctly individually,

  • 0

Working on a validation script for a clients site. Each function works correctly individually, but when I call them all from one function, the page still submits. Here is my code:

    <script type="text/javascript">

    function validateForm() {
      checkDate();
      checkRemainingFields();
      checkPhone();
    }

    /**--------------------------
    //* Validate Date Field script- By JavaScriptKit.com
    //* For this script and 100s more, visit http://www.javascriptkit.com
    //* This notice must stay intact for usage
    ---------------------------**/

    function checkDate(){
      var input=document.forms[0].eventdate;
      var validformat=/^\d{2}\/\d{2}\/\d{4}$/; //Basic check for format validity

      if (!validformat.test(input.value)) {
        alert("Invalid Day, Month, or Year range detected. Proper format is MM/DD/YYYY, please correct and submit again.")
        return false;
      } else{  //Detailed check for valid date ranges
      var monthfield=input.value.split("/")[0];
      var dayfield=input.value.split("/")[1];
      var yearfield=input.value.split("/")[2];
      var dayobj = new Date(yearfield, monthfield-1, dayfield);
    }

    if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) {
      alert("Invalid Day, Month, or Year range detected. Proper format is MM/DD/YYYY, please correct and submit again.")
      return false;
      } else return true;
    }

    function checkRemainingFields() {
      var theme=document.forms[0].theme;
      var text=document.forms[0].text;
      var name=document.forms[0].contactperson;

      if (theme.value.length==0) {
        alert("Invalid theme value.  Please correct the theme field to continue.");
        return false;
      } else if (text.value.length==0) {
        alert("Invalid description value. Please correct the desciption field to continue.");
        return false;
      } else if (name.value.length==0) {
        alert("Invalid name value.  Please correct the name field to continue.");
        return false;
      } else return true;
    }

    function checkPhone() {
      var input=document.forms[0].contactphone;
      var validformat=/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
      var ext=document.forms[0].extension;

      if (!validformat.test(input.value)) {
        alert("Invalid phone number detected. The proper format is 555-555-5555. Please correct and submit again.");
        return false;
      } else if (ext.value.length != 3){ //Check extension
        alert("Invalid extension.  Please type your 3 digit extension.");
        return false;
      } else return true;
    }

    </script>

validateForm() is called with an onsubmit from a form later on the page. I am not sure if I wrote the calls correctly. When the form is submitted, it goes through all of the checks and displays the alerts for each, but the page continues on to the php processing page. I need a bit of help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:21:16+00:00Added an answer on June 4, 2026 at 2:21 am

    Try something like:

    function validateForm() {
        return checkDate() && checkRemainingFields() && checkPhone();
    }
    

    You need to return false when any of those functions returns false, otherwise return true.

    An equivalent, though more verbose way is:

    function validateForm() {
        if (!checkDate()) return false;
        if (!checkRemainingFields()) return false;
        if (!checkPhone()) return false;
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a simple JavaScript validation function for a html form, but have
I'm working on a site with many forms, where I use jQuery Validation script.
I have jquery validation code which is working fine in ff but the same
I have fully working validation script my problem is that i can't get custom
I am putting server side validation but seems it's not working in the way
I'm working on a form validation script at work and am having some difficulty.
I'm working on a JQuery form validation script (first project - don't laugh) and
I am a PHP newbie and am working on a basic form validation script.
Background: I have a jQuery validation script, which is used on almost all my
I'm managed to get the validation working for the second step and third step

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.