Problems with searchable database

Hello,

I have created a searchable database for a company website. On a separate page, a text input and a table element are used. Upon clicking the Search button, the custom code looks up the database entry and refreshes the table. The issue I am having is that, when a user enters nothing, the table will display all items on the database. Below is the custom code I am utilizing.

import wixData from "wix-data";

$w.onReady(function () {
filter('0');
});

function filter(certnumber) {
    let newFilter = wixData.filter();
    newFilter = newFilter.contains('certno', certnumber);
    $w('#dataset1').setFilter(newFilter);
}

export function submitCert_click(event) {
    filter($w('#certInput').value);
    $w("#tableCert").refresh();
    $w("#tableCert").expand();
}

How can I make it so that when nothing is typed inside the text input box, no results will be displayed.
Also, when I add an input that corresponds to the first digits of a database entry (the one checked by the code), the code displays all entries with matching first 3 digits.

Thank you in advance!

So you are doing something similar to here and expanding the table when searched etc.
https://support.wix.com/en/article/corvid-tutorial-adding-collection-data-search-functionality#optionally-collapse-the-table-on-load-1

The easiest option would be to have the user inputs set as required so that a value must be entered into them, you can even disable the filter button until a value is entered etc.

Or you can do something in code along the lines of if there is no value in the box then do nothing else if there is a value in the box then run the filter.

Finally, as you are using contains in your query, it will return anything in the search that contains those entries anywhere it is used which could be start, middle, end, etc.

If you want it to match something exactly then use the eq function instead.