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;
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
add a comment |
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
Duplicate of stackoverflow.com/q/19966417/814160
– Sean the Bean
Oct 31 '16 at 16:16
add a comment |
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
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
html firefox
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
document.querySelector("input").addEventListener("keypress", function (evt)
if(evt.which == 8)return // to allow BackSpace
if (evt.which < 48 );
Number: <input type='number'>
add a comment |
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();
);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
document.querySelector("input").addEventListener("keypress", function (evt)
if(evt.which == 8)return // to allow BackSpace
if (evt.which < 48 );
Number: <input type='number'>
add a comment |
document.querySelector("input").addEventListener("keypress", function (evt)
if(evt.which == 8)return // to allow BackSpace
if (evt.which < 48 );
Number: <input type='number'>
add a comment |
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'>
document.querySelector("input").addEventListener("keypress", function (evt)
if(evt.which == 8)return // to allow BackSpace
if (evt.which < 48 );
Number: <input type='number'>
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
add a comment |
add a comment |
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();
);
add a comment |
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();
);
add a comment |
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();
);
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();
);
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
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Duplicate of stackoverflow.com/q/19966417/814160
– Sean the Bean
Oct 31 '16 at 16:16