I am working on creating a dynamic filter that can be used with just 3 letters. I have multiple fields that need to be filtered.
For instance, when searching for users by email, I want to be able to type "@gma" or "gma" and get back an array of all users matching the filter value. The same functionality should apply when filtering by properties like firstName.
Currently, my solution only works if I provide an exact match from the database, such as
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a7b6a0a793b4beb2babffdb0bcbe">[email protected]</a>
for email or "john" for firstName. I want to be able to search for "jo" and still get results for firstName.
const regexPattern = new RegExp(["^", filterUsersByValue, "$"].join(""), "i");
const filteredU = UserModel.find({ [filterUsersBy]: regexPattern})