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 8781933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:26:15+00:00 2026-06-13T20:26:15+00:00

I am validating form. It correctly validates all the field but when I enter

  • 0

I am validating form. It correctly validates all the field but when I enter correct data in text fields then still it does not process the data and return everything wrong whereas I want to it to return everything correct

Here is my js code

var url, container, form,
    View = {
        init: function () {
            container     = $('.container');
            $(document).on('submit', '#form', View.findView);
        },

        loadViews: function (view, flag, e) {
            e.preventDefault();
            var search = $('.search');

            if( flag ) {
                if ( View.validation.emptyFieldsValidation() == true ) {
                    console.log('everything correct');
                } else {
                    console.log('everything incorrect');
                }
            }
            return false;
        },

        validation: {
            emptyFieldsValidation: function () {
                var inputs, field;

                $('#form input').each(function (i, el) {
                    inputs = $(this);
                    if ( inputs.val() == '' ) {
                        inputs.css('border', '1px solid red');
                        return false;
                    } else {
                        inputs.css('border', '1px solid #ccc');
                        if (inputs.hasClass('from')) {
                            console.log('from');
                            if (View.validation.validateAddress(inputs.val())) {
                                console.log('from correct address');
                                return true;
                            }
                            else {
                                inputs.css('border', '1px solid red');
                                console.log('from incorrect address');
                                //return false;
                            }
                        }
                        if (inputs.hasClass('to')) {
                            console.log('to');
                            if (View.validation.validateAddress(inputs.val())) {
                                console.log('to correct address');
                                //return true;
                            }
                            else {
                                inputs.css('border', '1px solid red');
                                console.log('to incorrect address');
                                //return false;
                            }
                        }
                        if (inputs.hasClass('time')) {
                            if (View.validation.validateForNumber(inputs.val())) {
                                console.log('time correct');
                                //return true;
                            }
                            else {
                                inputs.css('border', '1px solid red');
                                console.log('time incorrect');
                                //return false;
                            }
                        }
                    }
                });
                return false;
            },

            validateAddress: function (val) {
                var streetregex = /^[\w+\s]+\d+,\s*[\s\w]+$/;
                if (streetregex.test(val)) return true;
                else return false;
            },

            validateForNumber: function (val) {
                if (!isNaN(val)) return true;
                else return false;
            }
        }
    };

View.init();

​
here is my html code

<section class="search">
<form id="form" action="">
    <section>
        <input type="text" name="from" class="from address" id="addressone" placeholder="From">
    </section>
    <section>
        <input type="text" name="to" class="to address" id="addresstwo" placeholder="To">
    </section>
    <section>
        <label>Time</label>
        <input type="text" name="hrs" placeholder="Hours" class="t1 time">
        <span>:</span>
        <input type="text" name="mins" placeholder="Mins" class="t1 time">
        <button class="button">Search</button>
    </section>
</form>
</section>

Update

I am getting this output in my console

screenshot

  • 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-13T20:26:16+00:00Added an answer on June 13, 2026 at 8:26 pm

    You seem to miss the fact that your emptyFieldsValidation function will always return false, as all the other return statements in its body are actually parts of ‘iterator’ function. Speaking of the latter, note that return false in $.each callback will stop the iteration.

    One possible way out of it is replacing all these return false statements in the iterator function with filling the array of validation errors instead. Then (after $.each line) you could check for its length (or just do return !!errors.length). For example:

    emptyFieldsValidation: function () {
      var errors = [];
      ...
      $('#form input').each(function() {
        if (! someValidationCheck) { 
          errors.push(someValidationAttribute);  
        }
      });
      ...
      return !!errors.length;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm validating my form, just checking if in the fields where a number should
When a form submit button is clicked, a function to validate all the field
I'm looking for a way to validate all the data on a form that
Does anyone know how to get the radio field type to validate correctly display
hi i have a text field in my HTML form . i want to
I am validating an HTML Form with PHP. All of my code is fine,
I have a form that calls on two separate models. My validation works correctly
I am currently using $.blur(fn();) for form validation, but this only takes effect when
I am validating a form and when there is any error in the textfield
I'm validating a form using the Validator interface with Spring MVC 3.0.2 using SimpleFormController

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.