Search: Prevent search inputs from including "@" character

1 Kommentare

  • Simon Celen
    Aktionen für Kommentare Permalink

    Hi Danny,

    On a stock Copenhagen theme the quick and dirty way would be:

    $('form.search').on('submit', function(e) {
    if ($('#query').val().indexOf('@') > -1) {
    e.preventDefault();
    alert('"@" sign not allowed in searches');
    }
    });

    This stops searches from going through if the query contains an "@".

    However, this solution is incomplete:

    • It doesn't really validate if the query is an email address. It only detects "@". 
    • The error message is delivered as a browser alert, which is crude. Better would be to show an HTML message under the search field, translated to the user's language if you're running a multilingual Help Center.
    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.

Powered by Zendesk