Search: Prevent search inputs from including "@" character


  • Simon Celen

    Hi Danny,

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

    $('').on('submit', function(e) {
    if ($('#query').val().indexOf('@') > -1) {
    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.

Please sign in to leave a comment.

Powered by Zendesk