I would like to have your help on it because I tried to solve it by myself so many times and I could not.
I have a combo box that has to be filtered by an input text entry.
The text in the combo is something like this:
004-83299-001 (AUC) Stateline Auto Auction
And I have a search by PDN (5h position to the 9th position = 83299 in this example), and by Dealer Name (from the 15th position to the end = (AUC) Stateline Auto Auction in this example).
When searching by the PDN it has to look just on those 5 positions and in the text it can find any text that starts with what I typed.
For example, if I type "line 299", it can not find the text, but if I type "832 State", it has to find it because of the PDN and part of the Dealer name text.
I am creating one Regular Expression object for each word entered in the text input field and applying them to both blocks of each line of combo box.
I used the following reg exp: (^|\s*) + text entered.
The problem with this approach is that it is looking for the text in any part of the string but I can work only with the beginning of the words.
Could anyone here please help me?
Thanks!
var vStringsToSearch = pattern.split(' ');
var vRegExpPatterns = new Array();
for (var i = 0; i < vStringsToSearch.length; i++)
{
vStringsToSearch[i] = '(^|\s*)' + vStringsToSearch[i].
replace(/([\\\^\$*+[\]?{}.=!|)])/g,"\\$1") + '.*';
try
{
// Initialize the regexp
vRegExpPatterns[i] = new RegExp(String(vStringsToSearch[i]), this.ignoreCaseFlag);
In fact if the user type 299 it has not to find anything expect if the 299 is in the Dealer Name.
It has to find the Dealer if I type "832 State" or "Auto 832". Something like this.
The PDN has to be looked at the begining of the text while the Dealer Name has to be looked at the whole string but only in the beginning of the texts.
I still don't understand what is your criteria but maybe this will help to get you started.
Code:
var combo = '004-83299-001 (AUC) Stateline Auto Auction';
var PDN = '832';
var dealer = 'Auto';
if (PDN && dealer) {
var reA = new RegExp('^.+?'+PDN+'.+?'+dealer+'.+$');
if (reA.test(combo)) { alert('found') } else { alert('not found'); }
}
else {
alert('invalid');
}
Bookmarks