SupremeA SupremeA - 1 year ago 76
jQuery Question

Show only a word from a string in autocomplete

I have an array of strings like so...

Array = ["WELLS FARGO DEALER May 18 06:11 4137 Reference# 10982",
"ONLINE - TRANSFER TO Ult SavingMay 18 03:57 4137 ONLINE Reference# 5929",
"Transfer From Checking 03:57a #4137 ONLINE Reference # 005929",

When I use jquery-ui autocomplete and the user starts to type a word or words, I want the autocomplete to only show the "WORD or WORDS" that matches the input so even if the string that matches is longer it only shows the matching word or words within that string. How can I select only matching words from within strings within in an array?

So if a user types
wells f
it should render
wells fargo
from the
"WELLS FARGO DEALER May 18 06:11 4137 Reference# 10982"

Answer Source

You could use a regexp like /#{text}([a-zA-Z]*)\b/, this will match all the text that's inputed and any other a-z chars until it reaches a word boundry.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download