I have an input for live search on JSON objects
<input type="input" id="searchtxt" placeholder="Search">
And here is my JS code
$('#searchtxt').keyup(function(){
var Field = $(this).val();
var regex = new RegExp(Field,"i");
$.each(data, function(key, val){
if (val.name.search(regex) != -1) {
//Do something
}
});
});
Having the i
as a flag I can only make my regex case sensitive but how can I also make it to match with accented characters because my JSON contains characters such as Ά,έ,Ί (Greek alphabet) etc.
For example:
var data = [
{"id":"1",
"name":"Παράδειγμα",
},
{"id":"2",
"name":"Ίδιο Κείμενο",
}];
So, if I search "Παραδέιγ" val.name.search(regex)
will return -1 cause of ά/έ but I want to have a match.