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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:04:12+00:00 2026-05-28T13:04:12+00:00

I have created a custom validation rule (uniqueUserName). The problem I’m having is that

  • 0

I have created a custom validation rule (uniqueUserName). The problem I’m having is that the error message is allways presented for the custom rule, even when returning true from the custom validation method.

The form I am trying to validate is loaded dynamically and added to divs.

Here’s where I add the method and defined the validation rules. The addValMethod is called after the page has been loaded but before attacheValidation:

 function addValMeth(){
               $.validator.addMethod("uniqueUserName", function(value, element) {

                    $.get("databasescripts/validate_username.php", {username: value}, function(data2){

                           alert("Validate-> " + data2);
                           if(data2 == "1"){
                               alert("Validate 2");
                               return true;                   

                           }else if(data2 == "0"){
                               alert("Validate 3");
                               return false;

                           }
                        });
               });
  };

 function attacheValidation($form){ 
          $($form).validate({ 
                  rules: { 
                      firstname: "required",// simple rule, converted to {required:true} 
                      surname: "required",
                      address: "required",
                      zipcode: "required",
                      city: "required",
                      email: {
                          required: true, 
                          email: true 
                      }, 
                      username: {
                           uniqueUserName: true,
                           required: true

                       }
                   }, 
                       messages: { 
                              firstname: "Förnamn saknas" ,
                              surname: "Efternamn saknas",
                              address: "Adress saknas",
                              zipcode: "Postkod saknas",
                              city: "Ort saknas",
                              companyname: "Företagsnamn saknas",
                              email: "Korrekt emailadress saknas",
                              username: {
                                  uniqueUserName: "Användarnamnet är upptaget",
                                  required: "Användarnamn saknas"

                             }
                            } 
                          }); 
                    };

The alerts proves the the logic in the custom validator works as it should. All other validation rules work properly.

I don’t know if it could be related, but everytime true result is returned, the custom validation method is requested two times. When it is false, the request to the method is made only once.

It’s the username field I want to apply the custom validation method on.

  • 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-28T13:04:12+00:00Added an answer on May 28, 2026 at 1:04 pm

    One has to do return “true” and return “false”. It expects a string not a boolean value.

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

Sidebar

Related Questions

I have a custom validation rule on a model that says the user can't
I have created a custom workflow activity that copies attachments from a case to
I have created a custom tag that looks like this: def textField = {
I have created a Custom Validation Attribute: public sealed class DateAttribute : DataTypeAttribute {
I have created a custom validation attribute by subclassing ValidationAttribute. The attribute is applied
I have created a custom Zend_Form with validators. After the validation and validation failed
Hopefully an easy one, I have created a Custom Repeater control that extends System.Web.UI.WebControls.Repeater.
I have created custom validation attribute [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited =
I have created a custom validator (below) that checks two textboxes to make sure
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and 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.