Pattern not working with readonly attributes











up vote
0
down vote

favorite












I have this form where user need to submit the num of days and it cannot be less than 1. So, I put a pattern there and with read only attribute.
My question is, why the pattern is not working when I put the readonly attribute? Let say, the numofdays is zero, supposedly when I submit, it will say the pattern is not match. But, when I put the readonly, the pattern is not working and the form is submitted even if the pattern is not correct. Is there any way that I can do this?



HTML



<form>

<input class="form-control" type="text" name="numofdays" id="id1" value="diffdays" pattern="[1-9]" title="No of days should not be less than 1" readonly>

<input type="submit" value="Submit" class="btn btn-primary">
</form>









share|improve this question


























    up vote
    0
    down vote

    favorite












    I have this form where user need to submit the num of days and it cannot be less than 1. So, I put a pattern there and with read only attribute.
    My question is, why the pattern is not working when I put the readonly attribute? Let say, the numofdays is zero, supposedly when I submit, it will say the pattern is not match. But, when I put the readonly, the pattern is not working and the form is submitted even if the pattern is not correct. Is there any way that I can do this?



    HTML



    <form>

    <input class="form-control" type="text" name="numofdays" id="id1" value="diffdays" pattern="[1-9]" title="No of days should not be less than 1" readonly>

    <input type="submit" value="Submit" class="btn btn-primary">
    </form>









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have this form where user need to submit the num of days and it cannot be less than 1. So, I put a pattern there and with read only attribute.
      My question is, why the pattern is not working when I put the readonly attribute? Let say, the numofdays is zero, supposedly when I submit, it will say the pattern is not match. But, when I put the readonly, the pattern is not working and the form is submitted even if the pattern is not correct. Is there any way that I can do this?



      HTML



      <form>

      <input class="form-control" type="text" name="numofdays" id="id1" value="diffdays" pattern="[1-9]" title="No of days should not be less than 1" readonly>

      <input type="submit" value="Submit" class="btn btn-primary">
      </form>









      share|improve this question













      I have this form where user need to submit the num of days and it cannot be less than 1. So, I put a pattern there and with read only attribute.
      My question is, why the pattern is not working when I put the readonly attribute? Let say, the numofdays is zero, supposedly when I submit, it will say the pattern is not match. But, when I put the readonly, the pattern is not working and the form is submitted even if the pattern is not correct. Is there any way that I can do this?



      HTML



      <form>

      <input class="form-control" type="text" name="numofdays" id="id1" value="diffdays" pattern="[1-9]" title="No of days should not be less than 1" readonly>

      <input type="submit" value="Submit" class="btn btn-primary">
      </form>






      html forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 9:17









      fatin amirah

      147




      147
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          That's by design.




          Constraint validation: If the readonly attribute is specified on an
          input element, the element is barred from constraint validation.




          Source: https://www.w3.org/TR/html5/forms.html#the-readonly-attribute






          share|improve this answer





















          • Ooh..Now I get it. Thank you for the explanation! :))
            – fatin amirah
            Nov 7 at 9:25











          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',
          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%2f53186475%2fpattern-not-working-with-readonly-attributes%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          That's by design.




          Constraint validation: If the readonly attribute is specified on an
          input element, the element is barred from constraint validation.




          Source: https://www.w3.org/TR/html5/forms.html#the-readonly-attribute






          share|improve this answer





















          • Ooh..Now I get it. Thank you for the explanation! :))
            – fatin amirah
            Nov 7 at 9:25















          up vote
          0
          down vote













          That's by design.




          Constraint validation: If the readonly attribute is specified on an
          input element, the element is barred from constraint validation.




          Source: https://www.w3.org/TR/html5/forms.html#the-readonly-attribute






          share|improve this answer





















          • Ooh..Now I get it. Thank you for the explanation! :))
            – fatin amirah
            Nov 7 at 9:25













          up vote
          0
          down vote










          up vote
          0
          down vote









          That's by design.




          Constraint validation: If the readonly attribute is specified on an
          input element, the element is barred from constraint validation.




          Source: https://www.w3.org/TR/html5/forms.html#the-readonly-attribute






          share|improve this answer












          That's by design.




          Constraint validation: If the readonly attribute is specified on an
          input element, the element is barred from constraint validation.




          Source: https://www.w3.org/TR/html5/forms.html#the-readonly-attribute







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 9:19









          maio290

          1,286314




          1,286314












          • Ooh..Now I get it. Thank you for the explanation! :))
            – fatin amirah
            Nov 7 at 9:25


















          • Ooh..Now I get it. Thank you for the explanation! :))
            – fatin amirah
            Nov 7 at 9:25
















          Ooh..Now I get it. Thank you for the explanation! :))
          – fatin amirah
          Nov 7 at 9:25




          Ooh..Now I get it. Thank you for the explanation! :))
          – fatin amirah
          Nov 7 at 9:25


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186475%2fpattern-not-working-with-readonly-attributes%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







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini