How to prohibit input to the input from a certain character (number 6)?

  • 0
    I serve certain IDs for "Something there".
    Each ID is unique and begins with a number that links the user to the geo.
    6 is India. I do not serve her. The rest, please.

    There is an input field where the user enters his ID to buy "something there".
    How to make him banned from entering from a certain digit ?! - That is, not completely ban the number 6, but only start with 6.
    He enters 6555 - not allowed.
    Introduces 5666 - for heaven's sake.

    Of course, it would be possible to make a mask, but the number of digits may be different (1234567 or 432526532)
    JavaScript Declan Serrano, Jun 24, 2019

  • 2 Answers
  • 0
    This sausage came out in the end ...: D



    jQuery(document).on("input", "#billing_idverif", function (event) {

    var input = event.currentTarget.value;
    var theLanguage = $('html').attr('lang');

    if (input.search(/^6/) != -1) {
    if ($("#tooltip").length === 0) {

    if ( theLanguage == "ru-RU" ) {$("<span class='tooltip' id='tooltip'><span class='tooltiptext'>ID, начинающиеся с цифры 6, не обслуживаются</span></span>").appendTo("#billing_idverif_field");}
    else {$("<span class='tooltip' id='tooltip'><span class='tooltiptext'>ID starting with 6 are not served</span></span>").appendTo("#billing_idverif_field");}
    $(".xt_woofc-checkout").css('opacity','0.5').css('pointer-events','none');
    $("#billing_idverif_field label").css('color', '#a00');
    $("#billing_idverif").css('border-color', '#a00');
    }
    }
    else
    {
    $("#tooltip").remove();
    $(".xt_woofc-checkout").css('opacity','1').css('pointer-events','auto').attr("href");

    if($("#billing_idverif").val() != ''){
    // Если поле не пустое удаляем класс-указание
    $("#billing_idverif_field label").css('color', '#4284ff');
    $("#billing_idverif").css('border-color', '#6dc22e');
    } else {
    // Если поле пустое
    }

    }
    });
    $("#billing_idverif").keydown(function (event) {
    if (event.keyCode == 46 || event.keyCode == {
    // Разрешаем backspace и delete
    } else {
    // Запрещаем вводить все, кроме цифр и tab
    if (event.keyCode !== 9 && event.keyCode !== 13 && event.keyCode !== 17 && event.keyCode !== 86 && (event.keyCode < 48 || event.keyCode > 57)) {
    event.preventDefault();
    }
    }
    });
    //Ограничение на длину поля 17 символов
    $("#billing_idverif").prop("maxlength", "17");
    Elliot Blanchard

  • 0
    In short, here's the regexp, and I hope you know what to do with it.

    / ^ [0-57-9] \ d {3,} $ /
    Ryan Forbes

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!