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

  • Home
  • SEARCH
  • 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 8715653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:53:57+00:00 2026-06-13T05:53:57+00:00

I have a simple class project where i’m doing some form validation. We have

  • 0

I have a simple class project where i’m doing some form validation. We have to use some basic regex expressions to validate input. I have this code in an external js file.

I have a function that captures the onsubmit event, and returns the value of the validation function of whether or not to proceed with the postback.

The problem is when i call the RegEx.test() method my validation functions stops and returns, and the postback proceeds inadvertently. Also strangly if i create a regex object using the “new RegEx()” the same thing happens. I’m lost as to why.

Here’s my code:

$(document).ready(function() {

    // onsubmit event    
    $('form').submit(
        function() {
            return validation();
        }
        );

    // form validation
    function validation() {

        resetErrors();

        //variables
        var validates = true;
        var errorString = "";
        //var isEmail = new RegEx('^.+@.+\..+$'); // function stops here if line is uncommented and kicks off the postback?
        //alert("harro new regex?"); // does not run if above line is uncommented


        var isEmail = "/^.+@.+\..+$/"; // this doesn't stop the function
        alert("harro isEmail direct regex string assignment"); // runs

        var isZipCode = "/^(\d{5}$)|(^\d{5}-\d{4}$)/"; // this doesn't stop the function
        alert("harro isZipCode direct regex string assignment"); // runs

        //firstname
        if (!$('#firstName').val().trim()) {
            validates = false;
            $('#firstName').addClass('error');
            errorString += "First Name is blank. <br />";
        }
        //lastname
        if (!$('#lastName').val().trim()) {
            validates = false;
            $('#lastName').addClass('error');
            errorString += "Last Name is blank. <br />";
        }
        //email
        if (!$('#email').val().trim()) {
            validates = false;
            errorString += "Email is blank. <br />";
            $('#email').addClass('error');
        }
        // if this runs the test, the function stops here
        else if (!isEmail.test(email.value)) {
            validates = false;
            errorString += "Please enter a valid email address. <br />";
            $('#email').addClass('error');
        }
        alert("harro rest of function after email test?")// does not run if "else if" is ran

        //address
        if (!$('#address').val().trim()) {
            validates = false;
            $('#address').addClass('error');
            errorString += "Address is blank. <br />";
        }

        //zipcode
        if (!$('#zipCode').val().trim()) {
            validates = false;
            $('#zipCode').addClass('error');
            errorString += "Zipcode is blank. <br />";
        }
        // if this runs the test, the function stops here
        else if (!isZipCode.test(zipCode.value)) {
            validates = false;
            $('#zipCode').addClass('error');
            errorString += "Please enter a valide zip code. <br />";
        }
        alert("harro rest of function after zipcide test?")// does not run if "else if" is ran


        if (validates) {
            return true;
        }

        //output error messages
        $('#pageTitle').after("<p id='errorText'>" + errorString + "</p>");

        return false;
    }

    //reset validation errors
    function resetErrors() {

        $('#errorText').remove();
        $('#firstName').removeClass('error');
        $('#lastName').removeClass('error');
        $('#email').removeClass('error');
        $('#address').removeClass('error');
        $('#zipCode').removeClass('error');

    }

});
  • 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-13T05:53:58+00:00Added an answer on June 13, 2026 at 5:53 am

    you are missing a “p”, it’s RegExp not RegEx

    var isEmail = new RegExp('^.+@.+\..+$');
    

    But in general with these problems, just have Firebug or Chrome Developer Tools open (F12 in windows) and then you will see the cause of the error. If you write new Regex() in the console, it will tell you that Regex is not defined, if you start writing RegE…, it will autocomplete it for you to RegExp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created a simple public ref class in the vc++ project, which is
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
I have a simple class for use on JNI, which i need to export
I have a simple class that contains some general information about the current web
I have a simple class library project (with Class1 ) and have enabled NuGet
Trying to unit test some simple code for a class project, however every time
I have a simple model: class Project < ActiveRecord::Base belongs_to :user class User <
I have a simple project in which I'm attempting to do some rewriting of
I have a very basic and simple class like this: unit Loader; interface uses
I'm switching from ActiveRecord to Dapper. I have a simple Project class with a

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.