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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:30:54+00:00 2026-05-15T19:30:54+00:00

I received some great help here the other day and hope once again I

  • 0

I received some great help here the other day and hope once again I can get the answer I need as Im pretty stuck right now. I have a form that has a text input (#USA_sub) and two subsequent text input’s (#FirstName) and (#LastName) I have a validation rule that checks to see if each value of (#FirstName) and (#LastName) each appear in (#USA_sub). What I have is working except for this: when you enter the correct value in the (#FirstName) input, correct in that it is contained in (#USA_sub) you only have to enter 2 letters in last name for it to validate. If you skip First Name it requires all of the last name as it should.

$.validator.addMethod(
    "firstSig", 
    function(value, element, params) {
        return $(params).val().indexOf(value + ' ' + $("#LastName").val()) > -1;
    }, 
    "Your first name must be contained in your Electronic Signature."
);

$.validator.addMethod(
    "lastSig", 
    function(value, element, params) {
        return $(params).val().indexOf($("#FirstName").val() + ' ' + value) > -1;
}, 
    "Your last name must be contained in your Electronic Signature."
);

and the validation rules:

                                  FirstName: {
                    required: true,
                    minlength: 2,
                    firstSig: "#USA_sub"
                },
                LastName: {
                    required: true,
                    minlength: 2,
                    lastSig: "#USA_sub"
                }
  • 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-15T19:30:54+00:00Added an answer on May 15, 2026 at 7:30 pm

    The reason it’s doing that is that you’re testing part of the name against the full name. As long as the target string contains consecutive characters matching the test string, there will be a match.

    For example:

    FirstName = Bob
    LastName = Dylan
    
    USA_sub = Bob Dylan
    
    user has typed: Bob Dyl
    

    There’s a match because the indexOf() found Bob Dyl within Bob Dylan

    Try just doing an == search, as in:

    return $(params).val() == ($("#FirstName").val() + ' ' + value);
    

    The reason your FirstName validator works, is that you’re concatenating in the space at the end.

    So Bo(space) is not found in Bob(space)Dylan. But Bob(space) is found in Bob(space)Dylan


    EDIT: New version that uses a regular expression to test for beginning/end of input, and eliminates the cross reference from FirstName to LastName and vice versa.

    The previous version didn’t work because you were always validating the FirstName and LastName against the FirstName field.

    Because of this, when you tab over to the LastName field, which is presumably empty, the validation fails for FirstName, and it doesn’t re-validate until you go back to the FirstName.

    What I did below was to remove the cross-field referencing, and use a regular expression so that we are able to test for beginning/end of line. So basically what we have is:

    FirstName tests for – BeginningOfInput + FirstName + space
    LastName tests for – space + LastName + EndOfInput

    $.validator.addMethod(
        "firstSig", 
        function(value, element, params) {
              // The regular expression represents
              //    beginning of input + value + space
            var regex = new RegExp('^' + value + ' ');
            return regex.test($(params).val());
        }, 
        "Your first name must be contained in your Electronic Signature."
    );
    
    $.validator.addMethod(
        "lastSig", 
        function(value, element, params) {
              // The regular expression represents
              //    space + value + end of input
            var regex = new RegExp(' ' + value + '$');
            return regex.test($(params).val());
    }, 
        "Your last name must be contained in your Electronic Signature."
    );
    

    This way you don’t get a validation failure when you’ve entered a correct FirstName, but haven’t yet gotten to the LastName field.

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

Sidebar

Related Questions

I need some code executed once per day. Can be more than once a
I received some great help on joining a table to itself and am trying
I have asked a question similar to this and received some great help, it
I just received some really great help today with a prior jQuery problem and
Flawed as I am, I've received some unneeded help in creating errors in the
We're developing a pretty large application with MVC 2 RC2 and we've received some
I'm back with another Flex/Flash security question. I've already received some help from the
Thanks to some help I received yesterday I've got some dynamic summing working on
hope you can help. I am recording audio from a microphone and streaming it
I've really hit a wall and am need of some help! Thankyou for reading

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.