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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:29:46+00:00 2026-05-21T17:29:46+00:00

I have an autocomplete box that (for the purposes of this example, since it’s

  • 0

I have an autocomplete box that (for the purposes of this example, since it’s a simple example) returns a list including social security numbers. These have dashes in them for readability. I want to modify the autocomplete so that if I put in “123456789” or “123-45-6789”, it will find the same entry in the autocomplete, without having to add both styles to the autocomplete source. I’ve been looking at adding a callback to search, but I’m drawing a blank on exactly how to accomplish this.

If I were using a search that pulled from an AJAX source, I could simply trim the input server-side and return whatever results I wanted. However, for speed’s sake, I’ve pre-loaded all of the data into the Javascript, so that option’s out.

Basically, I want to know how to trim dashes off autocomplete input before comparing it to the stored data (and, preferably, comparing it to a copy of the stored data also with dashes trimmed). There’s almost zero documentation on how to use the search: option, so I’m hoping someone can help.

  • 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-21T17:29:47+00:00Added an answer on May 21, 2026 at 5:29 pm

    One way to do this would be to provide a function to the source option of autocomplete:

    var ssn = ['123-45-6789', '333-44-5543', '111-34-9696', '555-99-5323'];
    
    $("#ssn").autocomplete({
        source: function(request, response) {
            /* Remove the dashes from the search term: */
            var term = request.term.replace(/-/g, '');
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), "i");
    
            response($.map(ssn, function(el) {
                /* Remove dashes from the source and compare with the term: */
                if (matcher.test(el.replace(/-/g, ''))) {
                    return el;
                }
            }));
        }
    });
    

    Here’s what’s going on:

    1. The source option takes a request and response parameter. Basically, you manipulate request.term (replace the dashes with an empty string) before comparing it with the list of valid values.

    2. Then, call the response function with the correct results. This example uses $.map to return a list of matches, comparing the term to each item in the list (without the “-“).

    Here’s a working example: http://jsfiddle.net/andrewwhitaker/r4SzC/

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

Sidebar

Related Questions

I have a simple jQuery/PHP autocomplete text box that gets the matches from mySQL.
In a text box, as you type, we have autocomplete that generates a list
I have autocomplete text box, that is JQuery based. when i record the macro,
I have a simple autocomplete field that spits out a bunch of suggested words
I have a search box on my site that uses autocomplete to give suggestions,
I have a functioning autocomplete box on my site that I want to work
I have an autocomplete combobox that creates a new select box based upon the
I have a jQuery UI Dialog Box that contains a jQuery UI Autocomplete input
I have a very large list of terms for use in an autocomplete box.
using jquery I have a autocomplete text box like the combobox example on the

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.