I want to restrict users from entering number ending with 5












-2

















Here is text field.I want users to only enter value like 210,220,230,... and restrict from entering something like 215,225,...



I am looking for suggetions.I don't have much knowledge of javascript.










share|improve this question




















  • 1





    What have you tried so far? put some code so we can have a better understand

    – Luis Cabrera Benito
    Nov 20 '18 at 18:53











  • <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text "/>

    – Aizaz Haider
    Nov 20 '18 at 18:54











  • I am looking for suggetions.I don't have much knowledge of javascript.

    – Aizaz Haider
    Nov 20 '18 at 18:55











  • Include all relevant code in your question, not in the comments.

    – Tim Lewis
    Nov 20 '18 at 18:55











  • Welcome to StackOverflow! Please review the FAQ on How to ask a good question to make sure you include the relevant information needed to answer your questions.

    – Tim
    Nov 20 '18 at 19:48
















-2

















Here is text field.I want users to only enter value like 210,220,230,... and restrict from entering something like 215,225,...



I am looking for suggetions.I don't have much knowledge of javascript.










share|improve this question




















  • 1





    What have you tried so far? put some code so we can have a better understand

    – Luis Cabrera Benito
    Nov 20 '18 at 18:53











  • <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text "/>

    – Aizaz Haider
    Nov 20 '18 at 18:54











  • I am looking for suggetions.I don't have much knowledge of javascript.

    – Aizaz Haider
    Nov 20 '18 at 18:55











  • Include all relevant code in your question, not in the comments.

    – Tim Lewis
    Nov 20 '18 at 18:55











  • Welcome to StackOverflow! Please review the FAQ on How to ask a good question to make sure you include the relevant information needed to answer your questions.

    – Tim
    Nov 20 '18 at 19:48














-2












-2








-2


1








Here is text field.I want users to only enter value like 210,220,230,... and restrict from entering something like 215,225,...



I am looking for suggetions.I don't have much knowledge of javascript.










share|improve this question


















Here is text field.I want users to only enter value like 210,220,230,... and restrict from entering something like 215,225,...



I am looking for suggetions.I don't have much knowledge of javascript.







javascript html forms text






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 18:58







Aizaz Haider

















asked Nov 20 '18 at 18:52









Aizaz HaiderAizaz Haider

11




11








  • 1





    What have you tried so far? put some code so we can have a better understand

    – Luis Cabrera Benito
    Nov 20 '18 at 18:53











  • <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text "/>

    – Aizaz Haider
    Nov 20 '18 at 18:54











  • I am looking for suggetions.I don't have much knowledge of javascript.

    – Aizaz Haider
    Nov 20 '18 at 18:55











  • Include all relevant code in your question, not in the comments.

    – Tim Lewis
    Nov 20 '18 at 18:55











  • Welcome to StackOverflow! Please review the FAQ on How to ask a good question to make sure you include the relevant information needed to answer your questions.

    – Tim
    Nov 20 '18 at 19:48














  • 1





    What have you tried so far? put some code so we can have a better understand

    – Luis Cabrera Benito
    Nov 20 '18 at 18:53











  • <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text "/>

    – Aizaz Haider
    Nov 20 '18 at 18:54











  • I am looking for suggetions.I don't have much knowledge of javascript.

    – Aizaz Haider
    Nov 20 '18 at 18:55











  • Include all relevant code in your question, not in the comments.

    – Tim Lewis
    Nov 20 '18 at 18:55











  • Welcome to StackOverflow! Please review the FAQ on How to ask a good question to make sure you include the relevant information needed to answer your questions.

    – Tim
    Nov 20 '18 at 19:48








1




1





What have you tried so far? put some code so we can have a better understand

– Luis Cabrera Benito
Nov 20 '18 at 18:53





What have you tried so far? put some code so we can have a better understand

– Luis Cabrera Benito
Nov 20 '18 at 18:53













<input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text "/>

– Aizaz Haider
Nov 20 '18 at 18:54





<input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text "/>

– Aizaz Haider
Nov 20 '18 at 18:54













I am looking for suggetions.I don't have much knowledge of javascript.

– Aizaz Haider
Nov 20 '18 at 18:55





I am looking for suggetions.I don't have much knowledge of javascript.

– Aizaz Haider
Nov 20 '18 at 18:55













Include all relevant code in your question, not in the comments.

– Tim Lewis
Nov 20 '18 at 18:55





Include all relevant code in your question, not in the comments.

– Tim Lewis
Nov 20 '18 at 18:55













Welcome to StackOverflow! Please review the FAQ on How to ask a good question to make sure you include the relevant information needed to answer your questions.

– Tim
Nov 20 '18 at 19:48





Welcome to StackOverflow! Please review the FAQ on How to ask a good question to make sure you include the relevant information needed to answer your questions.

– Tim
Nov 20 '18 at 19:48












3 Answers
3






active

oldest

votes


















0














If you just want to prevent strings that end in '5':



 document.getElementById("input").onblur = checkEND;

function checkEND() {
let firstValue = event.currentTarget.value;
if(firstValue.endsWith('5')){
warnUser()
}
}


This won't validate that the string is a valid number though.






share|improve this answer


























  • add some description what is your solution about

    – Alex
    Nov 20 '18 at 19:27



















0

















function testInput() {
var key = window.event.keyCode;
var x = document.getElementById('textarea').value
var y = document.getElementById('textarea2').value
var z = parseInt(x, 10);
if (z+10 == y) {
document.getElementById('result').innerHTML = "valid";
} else {
document.getElementById('result').innerHTML = "invalid";
}
}

<textarea maxlength="3" id="textarea">5</textarea>
<textarea maxlength="3" id="textarea2">15</textarea>
<button onclick="testInput()">Test Input</button>
<div id="result"></div>





The first input is your first number, the second is your second number.
See Comments If Your Wondering Why This Doesn't Answer His OG Question






share|improve this answer


























  • This block all fives. But OP wants number ending with 5

    – Smollet777
    Nov 20 '18 at 19:14











  • I updated the code.

    – BGM52
    Nov 20 '18 at 19:22











  • Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

    – Aizaz Haider
    Nov 20 '18 at 19:36











  • So do you want the users input to be a list of numbers that all have the same increment?

    – BGM52
    Nov 20 '18 at 19:38











  • yes .Incremnt of 10.

    – Aizaz Haider
    Nov 20 '18 at 19:40



















0














You can experiment with the setCustomValidity() of input elements (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) from an onblur, onchange or oninput handler. If you are not satisfied with the value, set an error message, and an empty string otherwise. As long as the error message is set to non-empty, it is displayed and the form refuses to submit:






function check5() {
cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
}

<form>
<input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
<input type="submit" value="Send">
</form>





(StackOverflow snippets interfere with form submission - probably as part of security -, so successful submission just makes the form disappear)





As setCustomValidity() does not work everywhere (according to the compatibility table, it will not work on non-Andorid mobiles), classic "budget" solution may be mentioned too: you can simply disable the send button as long as you are not satisfied with the input:






function check5() {
if(cgiftcardq.value.endsWith('5')){
send.disabled=true;
message.innerHTML="Nope, it can not end with 5";
} else {
send.disabled=false;
message.innerHTML="OK";
}
}

<form>
<input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
<input id="send" type="submit" value="Send" disabled>
</form>
<div id="message"></div>








share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399669%2fi-want-to-restrict-users-from-entering-number-ending-with-5%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you just want to prevent strings that end in '5':



     document.getElementById("input").onblur = checkEND;

    function checkEND() {
    let firstValue = event.currentTarget.value;
    if(firstValue.endsWith('5')){
    warnUser()
    }
    }


    This won't validate that the string is a valid number though.






    share|improve this answer


























    • add some description what is your solution about

      – Alex
      Nov 20 '18 at 19:27
















    0














    If you just want to prevent strings that end in '5':



     document.getElementById("input").onblur = checkEND;

    function checkEND() {
    let firstValue = event.currentTarget.value;
    if(firstValue.endsWith('5')){
    warnUser()
    }
    }


    This won't validate that the string is a valid number though.






    share|improve this answer


























    • add some description what is your solution about

      – Alex
      Nov 20 '18 at 19:27














    0












    0








    0







    If you just want to prevent strings that end in '5':



     document.getElementById("input").onblur = checkEND;

    function checkEND() {
    let firstValue = event.currentTarget.value;
    if(firstValue.endsWith('5')){
    warnUser()
    }
    }


    This won't validate that the string is a valid number though.






    share|improve this answer















    If you just want to prevent strings that end in '5':



     document.getElementById("input").onblur = checkEND;

    function checkEND() {
    let firstValue = event.currentTarget.value;
    if(firstValue.endsWith('5')){
    warnUser()
    }
    }


    This won't validate that the string is a valid number though.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 20 '18 at 19:38









    Azmisov

    2,28342952




    2,28342952










    answered Nov 20 '18 at 18:59









    user18984user18984

    375




    375













    • add some description what is your solution about

      – Alex
      Nov 20 '18 at 19:27



















    • add some description what is your solution about

      – Alex
      Nov 20 '18 at 19:27

















    add some description what is your solution about

    – Alex
    Nov 20 '18 at 19:27





    add some description what is your solution about

    – Alex
    Nov 20 '18 at 19:27













    0

















    function testInput() {
    var key = window.event.keyCode;
    var x = document.getElementById('textarea').value
    var y = document.getElementById('textarea2').value
    var z = parseInt(x, 10);
    if (z+10 == y) {
    document.getElementById('result').innerHTML = "valid";
    } else {
    document.getElementById('result').innerHTML = "invalid";
    }
    }

    <textarea maxlength="3" id="textarea">5</textarea>
    <textarea maxlength="3" id="textarea2">15</textarea>
    <button onclick="testInput()">Test Input</button>
    <div id="result"></div>





    The first input is your first number, the second is your second number.
    See Comments If Your Wondering Why This Doesn't Answer His OG Question






    share|improve this answer


























    • This block all fives. But OP wants number ending with 5

      – Smollet777
      Nov 20 '18 at 19:14











    • I updated the code.

      – BGM52
      Nov 20 '18 at 19:22











    • Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

      – Aizaz Haider
      Nov 20 '18 at 19:36











    • So do you want the users input to be a list of numbers that all have the same increment?

      – BGM52
      Nov 20 '18 at 19:38











    • yes .Incremnt of 10.

      – Aizaz Haider
      Nov 20 '18 at 19:40
















    0

















    function testInput() {
    var key = window.event.keyCode;
    var x = document.getElementById('textarea').value
    var y = document.getElementById('textarea2').value
    var z = parseInt(x, 10);
    if (z+10 == y) {
    document.getElementById('result').innerHTML = "valid";
    } else {
    document.getElementById('result').innerHTML = "invalid";
    }
    }

    <textarea maxlength="3" id="textarea">5</textarea>
    <textarea maxlength="3" id="textarea2">15</textarea>
    <button onclick="testInput()">Test Input</button>
    <div id="result"></div>





    The first input is your first number, the second is your second number.
    See Comments If Your Wondering Why This Doesn't Answer His OG Question






    share|improve this answer


























    • This block all fives. But OP wants number ending with 5

      – Smollet777
      Nov 20 '18 at 19:14











    • I updated the code.

      – BGM52
      Nov 20 '18 at 19:22











    • Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

      – Aizaz Haider
      Nov 20 '18 at 19:36











    • So do you want the users input to be a list of numbers that all have the same increment?

      – BGM52
      Nov 20 '18 at 19:38











    • yes .Incremnt of 10.

      – Aizaz Haider
      Nov 20 '18 at 19:40














    0












    0








    0










    function testInput() {
    var key = window.event.keyCode;
    var x = document.getElementById('textarea').value
    var y = document.getElementById('textarea2').value
    var z = parseInt(x, 10);
    if (z+10 == y) {
    document.getElementById('result').innerHTML = "valid";
    } else {
    document.getElementById('result').innerHTML = "invalid";
    }
    }

    <textarea maxlength="3" id="textarea">5</textarea>
    <textarea maxlength="3" id="textarea2">15</textarea>
    <button onclick="testInput()">Test Input</button>
    <div id="result"></div>





    The first input is your first number, the second is your second number.
    See Comments If Your Wondering Why This Doesn't Answer His OG Question






    share|improve this answer


















    function testInput() {
    var key = window.event.keyCode;
    var x = document.getElementById('textarea').value
    var y = document.getElementById('textarea2').value
    var z = parseInt(x, 10);
    if (z+10 == y) {
    document.getElementById('result').innerHTML = "valid";
    } else {
    document.getElementById('result').innerHTML = "invalid";
    }
    }

    <textarea maxlength="3" id="textarea">5</textarea>
    <textarea maxlength="3" id="textarea2">15</textarea>
    <button onclick="testInput()">Test Input</button>
    <div id="result"></div>





    The first input is your first number, the second is your second number.
    See Comments If Your Wondering Why This Doesn't Answer His OG Question






    function testInput() {
    var key = window.event.keyCode;
    var x = document.getElementById('textarea').value
    var y = document.getElementById('textarea2').value
    var z = parseInt(x, 10);
    if (z+10 == y) {
    document.getElementById('result').innerHTML = "valid";
    } else {
    document.getElementById('result').innerHTML = "invalid";
    }
    }

    <textarea maxlength="3" id="textarea">5</textarea>
    <textarea maxlength="3" id="textarea2">15</textarea>
    <button onclick="testInput()">Test Input</button>
    <div id="result"></div>





    function testInput() {
    var key = window.event.keyCode;
    var x = document.getElementById('textarea').value
    var y = document.getElementById('textarea2').value
    var z = parseInt(x, 10);
    if (z+10 == y) {
    document.getElementById('result').innerHTML = "valid";
    } else {
    document.getElementById('result').innerHTML = "invalid";
    }
    }

    <textarea maxlength="3" id="textarea">5</textarea>
    <textarea maxlength="3" id="textarea2">15</textarea>
    <button onclick="testInput()">Test Input</button>
    <div id="result"></div>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 20 '18 at 19:47

























    answered Nov 20 '18 at 19:03









    BGM52BGM52

    328




    328













    • This block all fives. But OP wants number ending with 5

      – Smollet777
      Nov 20 '18 at 19:14











    • I updated the code.

      – BGM52
      Nov 20 '18 at 19:22











    • Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

      – Aizaz Haider
      Nov 20 '18 at 19:36











    • So do you want the users input to be a list of numbers that all have the same increment?

      – BGM52
      Nov 20 '18 at 19:38











    • yes .Incremnt of 10.

      – Aizaz Haider
      Nov 20 '18 at 19:40



















    • This block all fives. But OP wants number ending with 5

      – Smollet777
      Nov 20 '18 at 19:14











    • I updated the code.

      – BGM52
      Nov 20 '18 at 19:22











    • Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

      – Aizaz Haider
      Nov 20 '18 at 19:36











    • So do you want the users input to be a list of numbers that all have the same increment?

      – BGM52
      Nov 20 '18 at 19:38











    • yes .Incremnt of 10.

      – Aizaz Haider
      Nov 20 '18 at 19:40

















    This block all fives. But OP wants number ending with 5

    – Smollet777
    Nov 20 '18 at 19:14





    This block all fives. But OP wants number ending with 5

    – Smollet777
    Nov 20 '18 at 19:14













    I updated the code.

    – BGM52
    Nov 20 '18 at 19:22





    I updated the code.

    – BGM52
    Nov 20 '18 at 19:22













    Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

    – Aizaz Haider
    Nov 20 '18 at 19:36





    Is there a possible way that user can only enter the number incremnt of 10 like 210,220,230 ,.....??

    – Aizaz Haider
    Nov 20 '18 at 19:36













    So do you want the users input to be a list of numbers that all have the same increment?

    – BGM52
    Nov 20 '18 at 19:38





    So do you want the users input to be a list of numbers that all have the same increment?

    – BGM52
    Nov 20 '18 at 19:38













    yes .Incremnt of 10.

    – Aizaz Haider
    Nov 20 '18 at 19:40





    yes .Incremnt of 10.

    – Aizaz Haider
    Nov 20 '18 at 19:40











    0














    You can experiment with the setCustomValidity() of input elements (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) from an onblur, onchange or oninput handler. If you are not satisfied with the value, set an error message, and an empty string otherwise. As long as the error message is set to non-empty, it is displayed and the form refuses to submit:






    function check5() {
    cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
    }

    <form>
    <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
    <input type="submit" value="Send">
    </form>





    (StackOverflow snippets interfere with form submission - probably as part of security -, so successful submission just makes the form disappear)





    As setCustomValidity() does not work everywhere (according to the compatibility table, it will not work on non-Andorid mobiles), classic "budget" solution may be mentioned too: you can simply disable the send button as long as you are not satisfied with the input:






    function check5() {
    if(cgiftcardq.value.endsWith('5')){
    send.disabled=true;
    message.innerHTML="Nope, it can not end with 5";
    } else {
    send.disabled=false;
    message.innerHTML="OK";
    }
    }

    <form>
    <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
    <input id="send" type="submit" value="Send" disabled>
    </form>
    <div id="message"></div>








    share|improve this answer






























      0














      You can experiment with the setCustomValidity() of input elements (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) from an onblur, onchange or oninput handler. If you are not satisfied with the value, set an error message, and an empty string otherwise. As long as the error message is set to non-empty, it is displayed and the form refuses to submit:






      function check5() {
      cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
      }

      <form>
      <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
      <input type="submit" value="Send">
      </form>





      (StackOverflow snippets interfere with form submission - probably as part of security -, so successful submission just makes the form disappear)





      As setCustomValidity() does not work everywhere (according to the compatibility table, it will not work on non-Andorid mobiles), classic "budget" solution may be mentioned too: you can simply disable the send button as long as you are not satisfied with the input:






      function check5() {
      if(cgiftcardq.value.endsWith('5')){
      send.disabled=true;
      message.innerHTML="Nope, it can not end with 5";
      } else {
      send.disabled=false;
      message.innerHTML="OK";
      }
      }

      <form>
      <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
      <input id="send" type="submit" value="Send" disabled>
      </form>
      <div id="message"></div>








      share|improve this answer




























        0












        0








        0







        You can experiment with the setCustomValidity() of input elements (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) from an onblur, onchange or oninput handler. If you are not satisfied with the value, set an error message, and an empty string otherwise. As long as the error message is set to non-empty, it is displayed and the form refuses to submit:






        function check5() {
        cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
        <input type="submit" value="Send">
        </form>





        (StackOverflow snippets interfere with form submission - probably as part of security -, so successful submission just makes the form disappear)





        As setCustomValidity() does not work everywhere (according to the compatibility table, it will not work on non-Andorid mobiles), classic "budget" solution may be mentioned too: you can simply disable the send button as long as you are not satisfied with the input:






        function check5() {
        if(cgiftcardq.value.endsWith('5')){
        send.disabled=true;
        message.innerHTML="Nope, it can not end with 5";
        } else {
        send.disabled=false;
        message.innerHTML="OK";
        }
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
        <input id="send" type="submit" value="Send" disabled>
        </form>
        <div id="message"></div>








        share|improve this answer















        You can experiment with the setCustomValidity() of input elements (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) from an onblur, onchange or oninput handler. If you are not satisfied with the value, set an error message, and an empty string otherwise. As long as the error message is set to non-empty, it is displayed and the form refuses to submit:






        function check5() {
        cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
        <input type="submit" value="Send">
        </form>





        (StackOverflow snippets interfere with form submission - probably as part of security -, so successful submission just makes the form disappear)





        As setCustomValidity() does not work everywhere (according to the compatibility table, it will not work on non-Andorid mobiles), classic "budget" solution may be mentioned too: you can simply disable the send button as long as you are not satisfied with the input:






        function check5() {
        if(cgiftcardq.value.endsWith('5')){
        send.disabled=true;
        message.innerHTML="Nope, it can not end with 5";
        } else {
        send.disabled=false;
        message.innerHTML="OK";
        }
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
        <input id="send" type="submit" value="Send" disabled>
        </form>
        <div id="message"></div>








        function check5() {
        cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
        <input type="submit" value="Send">
        </form>





        function check5() {
        cgiftcardq.setCustomValidity(cgiftcardq.value.endsWith('5')?"Nope, it can not end with 5":"");
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" onblur="check5()">
        <input type="submit" value="Send">
        </form>





        function check5() {
        if(cgiftcardq.value.endsWith('5')){
        send.disabled=true;
        message.innerHTML="Nope, it can not end with 5";
        } else {
        send.disabled=false;
        message.innerHTML="OK";
        }
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
        <input id="send" type="submit" value="Send" disabled>
        </form>
        <div id="message"></div>





        function check5() {
        if(cgiftcardq.value.endsWith('5')){
        send.disabled=true;
        message.innerHTML="Nope, it can not end with 5";
        } else {
        send.disabled=false;
        message.innerHTML="OK";
        }
        }

        <form>
        <input name="cgiftcardq" class="text_field" id="cgiftcardq" size="3" autocomplete="off" type="text" oninput="check5()">
        <input id="send" type="submit" value="Send" disabled>
        </form>
        <div id="message"></div>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 11:53

























        answered Nov 20 '18 at 19:29









        tevemadartevemadar

        4,2982723




        4,2982723






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399669%2fi-want-to-restrict-users-from-entering-number-ending-with-5%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?