prevent displaying of non numeric characters for input type number in mozillaPrevent typing non-numeric in input type numberHow to make HTML input tag only accept numerical values?Prevent typing non-numeric in input type numberDifferentiate between NaN input and empty input with an Input of type=“number”How can i restrict user from entering the numeric and special characters in textbox?Get off-type content from html inputPrevent negative inputs in form input type=“number”?Function to Detect non-numerical characters not workingPreventing users from entering non-digits in input text field with HTML5Prevent typing non-numeric in input field on mobile browserJavaScript filter non-digits on paste event in Firefox

Word for an event that will likely never happen again

Generate Brainfuck for the numbers 1–255

How do I call a 6 digit Austrailian phone number with a US based mobile phone?

What are these funnel-looking green things in my yard?

How make an image of my entire usb flash drive?

A torrent of foreign terms

What's this phrase on the wall of a toilet of a French château ?

Escape Velocity - Won't the orbital path just become larger with higher initial velocity?

Do beef farmed pastures net remove carbon emissions?

Why is the Lucas test not recommended to differentiate higher alcohols?

What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?

What is the farthest a camera can see?

Graphs for which a calculus student can reasonably compute the arclength

Are differences between uniformly distributed numbers uniformly distributed?

Can renaming a method preserve encapsulation?

Can sampling rate be a floating point number?

Do I have to cite common CS algorithms?

Submitting a new paper just after another was accepted by the same journal

Why is Python 2.7 still the default Python version in Ubuntu?

What is a good class if we remove subclasses?

Are there any other rule mechanics that could grant Thieves' Cant?

If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?

Modeling the uncertainty of the input parameters

Boss asked a co-worker to assault me



prevent displaying of non numeric characters for input type number in mozilla


Prevent typing non-numeric in input type numberHow to make HTML input tag only accept numerical values?Prevent typing non-numeric in input type numberDifferentiate between NaN input and empty input with an Input of type=“number”How can i restrict user from entering the numeric and special characters in textbox?Get off-type content from html inputPrevent negative inputs in form input type=“number”?Function to Detect non-numerical characters not workingPreventing users from entering non-digits in input text field with HTML5Prevent typing non-numeric in input field on mobile browserJavaScript filter non-digits on paste event in Firefox






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















In chrome, when we use <input type='number'>, if we type any non numeric characters, they are not displayed.



In mozilla, they are displayed. However, when I get e.target.value, I am getting an empty string with a validation message Please enter an number.



I want the chrome functionality in mozilla - I am trying to strip out the last character if it is not numeric - but as the value is empty string as soon as non numeric character is entered I am unable to do so.










share|improve this question
























  • Duplicate of stackoverflow.com/q/19966417/814160

    – Sean the Bean
    Oct 31 '16 at 16:16

















1















In chrome, when we use <input type='number'>, if we type any non numeric characters, they are not displayed.



In mozilla, they are displayed. However, when I get e.target.value, I am getting an empty string with a validation message Please enter an number.



I want the chrome functionality in mozilla - I am trying to strip out the last character if it is not numeric - but as the value is empty string as soon as non numeric character is entered I am unable to do so.










share|improve this question
























  • Duplicate of stackoverflow.com/q/19966417/814160

    – Sean the Bean
    Oct 31 '16 at 16:16













1












1








1








In chrome, when we use <input type='number'>, if we type any non numeric characters, they are not displayed.



In mozilla, they are displayed. However, when I get e.target.value, I am getting an empty string with a validation message Please enter an number.



I want the chrome functionality in mozilla - I am trying to strip out the last character if it is not numeric - but as the value is empty string as soon as non numeric character is entered I am unable to do so.










share|improve this question














In chrome, when we use <input type='number'>, if we type any non numeric characters, they are not displayed.



In mozilla, they are displayed. However, when I get e.target.value, I am getting an empty string with a validation message Please enter an number.



I want the chrome functionality in mozilla - I am trying to strip out the last character if it is not numeric - but as the value is empty string as soon as non numeric character is entered I am unable to do so.







html firefox






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 21 '15 at 14:33









user2133404user2133404

7154 gold badges19 silver badges40 bronze badges




7154 gold badges19 silver badges40 bronze badges















  • Duplicate of stackoverflow.com/q/19966417/814160

    – Sean the Bean
    Oct 31 '16 at 16:16

















  • Duplicate of stackoverflow.com/q/19966417/814160

    – Sean the Bean
    Oct 31 '16 at 16:16
















Duplicate of stackoverflow.com/q/19966417/814160

– Sean the Bean
Oct 31 '16 at 16:16





Duplicate of stackoverflow.com/q/19966417/814160

– Sean the Bean
Oct 31 '16 at 16:16












2 Answers
2






active

oldest

votes


















1

















document.querySelector("input").addEventListener("keypress", function (evt) 
if(evt.which == 8)return // to allow BackSpace
if (evt.which < 48 );

Number: <input type='number'>








share|improve this answer


































    0














    You could do something like this:
    http://jsfiddle.net/zpg8k/1660/



    $('input[type="number"]').keypress(function(e) 
    var a = [];
    var k = e.which;

    for (i = 48; i < 58; i++)
    a.push(i);

    if (!(a.indexOf(k)>=0))
    e.preventDefault();
    );





    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%2f32143018%2fprevent-displaying-of-non-numeric-characters-for-input-type-number-in-mozilla%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1

















      document.querySelector("input").addEventListener("keypress", function (evt) 
      if(evt.which == 8)return // to allow BackSpace
      if (evt.which < 48 );

      Number: <input type='number'>








      share|improve this answer































        1

















        document.querySelector("input").addEventListener("keypress", function (evt) 
        if(evt.which == 8)return // to allow BackSpace
        if (evt.which < 48 );

        Number: <input type='number'>








        share|improve this answer





























          1












          1








          1










          document.querySelector("input").addEventListener("keypress", function (evt) 
          if(evt.which == 8)return // to allow BackSpace
          if (evt.which < 48 );

          Number: <input type='number'>








          share|improve this answer


















          document.querySelector("input").addEventListener("keypress", function (evt) 
          if(evt.which == 8)return // to allow BackSpace
          if (evt.which < 48 );

          Number: <input type='number'>








          document.querySelector("input").addEventListener("keypress", function (evt) 
          if(evt.which == 8)return // to allow BackSpace
          if (evt.which < 48 );

          Number: <input type='number'>





          document.querySelector("input").addEventListener("keypress", function (evt) 
          if(evt.which == 8)return // to allow BackSpace
          if (evt.which < 48 );

          Number: <input type='number'>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 21 '15 at 15:24

























          answered Aug 21 '15 at 14:54









          MuhammadMuhammad

          2,4102 gold badges18 silver badges35 bronze badges




          2,4102 gold badges18 silver badges35 bronze badges


























              0














              You could do something like this:
              http://jsfiddle.net/zpg8k/1660/



              $('input[type="number"]').keypress(function(e) 
              var a = [];
              var k = e.which;

              for (i = 48; i < 58; i++)
              a.push(i);

              if (!(a.indexOf(k)>=0))
              e.preventDefault();
              );





              share|improve this answer































                0














                You could do something like this:
                http://jsfiddle.net/zpg8k/1660/



                $('input[type="number"]').keypress(function(e) 
                var a = [];
                var k = e.which;

                for (i = 48; i < 58; i++)
                a.push(i);

                if (!(a.indexOf(k)>=0))
                e.preventDefault();
                );





                share|improve this answer





























                  0












                  0








                  0







                  You could do something like this:
                  http://jsfiddle.net/zpg8k/1660/



                  $('input[type="number"]').keypress(function(e) 
                  var a = [];
                  var k = e.which;

                  for (i = 48; i < 58; i++)
                  a.push(i);

                  if (!(a.indexOf(k)>=0))
                  e.preventDefault();
                  );





                  share|improve this answer















                  You could do something like this:
                  http://jsfiddle.net/zpg8k/1660/



                  $('input[type="number"]').keypress(function(e) 
                  var a = [];
                  var k = e.which;

                  for (i = 48; i < 58; i++)
                  a.push(i);

                  if (!(a.indexOf(k)>=0))
                  e.preventDefault();
                  );






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 21 '15 at 14:42

























                  answered Aug 21 '15 at 14:37









                  justtryjusttry

                  5993 silver badges8 bronze badges




                  5993 silver badges8 bronze badges






























                      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%2f32143018%2fprevent-displaying-of-non-numeric-characters-for-input-type-number-in-mozilla%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript