when a user enters a hex number for example b1b1b1, add the # symbol if he forgot to write. html:

<input type="text" class="color-scheme__input-color"> 

    1 answer 1

    As an option (IE 11+):

     let input = document.querySelector("input"); input.addEventListener("change", function() { if (this.value[0] != '#') { this.value = '#' + this.value; } }); 
     <input type="text"> 

    Need a jQuery translation?

    UPD

     $("input").on("change", function() { let $me = $(this); if ($me.val()[0] != "#") { $me.val( "#" + $me.val() ) } }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text"> 

    • If not difficult, then you can option in jquery - Dima Vleskov
    • @DimaVleskov Updated answer - Oleg