my function below searches a table, currently it searches for anything like, i want it to do an exact match, could you help me out?
Thanks
function searchTable(inputVal, tablename) {
var table = $(tablename);
table.find('tr:not(.header)').each(function (index, row) {
var allCells = $(row).find('td');
if (allCells.length > 0) {
var found = false;
allCells.each(function (index, td) {
var regExp = new RegExp(inputVal, 'i');
if (regExp.test($(td).text())) {
found = true;
return false;
}
});
if (found == true) $(row).show().removeClass('exclude'); else $(row).hide().addClass('exclude');
}
});
}
Your current Regex is case insensitive. An exact match would imply case sensitivity.
var regExp = new RegExp("^" + inputVal + "$", 'i'); // case insensitive
or
var regExp = new RegExp("^" + inputVal + "$"); // case sensitive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With