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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:40:44+00:00 2026-05-23T12:40:44+00:00

So I have a custom validator checking an inputted zipcode against my database of

  • 0

So I have a custom validator checking an inputted zipcode against my database of acceptable zip codes.

My custom method is as follows:

jQuery.validator.addMethod("validZip", function(value, element){
    var _id = $(element).attr("id");
    $.post(
        '/xpress/wp-admin/admin-ajax.php',
        {action:"test_checkZip", zip:value},
        function(response){
            if (result == 0){
                return false;
            } else {
                return true;
            }
        }
    );
}, '*');

The problem, I believe, is that since ajax is non-blocking the latency of the request doesnt return the true/false result for the validator in time for it to be recognized.

Whenever the result should be true, it fails to hide the error message and the form fails to ever be submittable.

I’ve been able to hide the error message in the return true code block by explicitly hiding the error element. The error message does hide, however, the form still returns false since the custom method fails to ever return true.

Have I done something wrong? How can I get around this issue?

Many thanks.

  • 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-05-23T12:40:45+00:00Added an answer on May 23, 2026 at 12:40 pm

    You could use a synchronous recuest using $.ajax

    jQuery.validator.addMethod("validZip", function(value, element){
        var _id = $(element).attr("id");
        var return_val = null;
        $.ajax({
            url: '/xpress/wp-admin/admin-ajax.php',
            type: 'post',
            data: {action:"test_checkZip", zip:value},
            async: false,  //This does the trick
            success: function(response){
                if (result == 0){
                    return_val = false;
                } else {
                    return_val = true;
                }
            }
        });
        return return_val;
    }, '*');
    

    Hope this helps. Cheers

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

Sidebar

Related Questions

I have a custom validator checking a value against a database of acceptable values
I have a custom validator method that will check an inputted zip code against
I have a custom validator attached to a textbox control as follows <td align=center
I have a custom validator that points to a Client side script to validate
I have a custom validation in the enterprise validation block. The DoValidate method is
I have a custom validator that does validation based on the thumbprint of the
Is there a way to have the custom validator take the input from two
I have one problematic question on custom validator at client side in asp.net? This
HI i have custom validator which is to compare the value in 2 textboxes
I have written a custom Validator that expects an attribute to be set. I

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.