sasha85
asked on
only numbers allowed
<input type="text" onKeyUp="if (isNaN(this.value)) this.value=this.value.repl ace(/[^0-9 .]/g,'')">
this do the work partly cause it leaves the point...
this do the work partly cause it leaves the point...
ASKER
"no point"
What is the problem? The solution is from the question ErikTsomik pointed to. Is there a problem?
What character are you putting in that is getting past the script or causing some other problem?
If you don't want to allow the decimal point then just remove it and use ...
<input type="text" onKeyUp="if (isNaN(this.value)) this.value=this.value.repl ace(/[^0-9 ]/g,'')">
Let me know if you have a question or need more info.
bol
What character are you putting in that is getting past the script or causing some other problem?
If you don't want to allow the decimal point then just remove it and use ...
<input type="text" onKeyUp="if (isNaN(this.value)) this.value=this.value.repl
Let me know if you have a question or need more info.
bol
that it supposed to be because it displays money value and it can contains pennies
ASKER
i need to display/insert 10 numbers...that why i do not need this point:)
Do you need to test for 10 numbers? If you just want to remove the period and all other non-numeric characters then use the html and script I modified. It will do that.
bol
bol
input type="text" onKeyUp="if (isNaN(this.value)) this.value=this.value.repl ace(/[^0-9 ]/g,'')">
erikTsomik,
Did you notice http:#20387106 ? Your post copies the contents of mine. Please either give credit or read previous comments more carefully. Hopefully it was just a mistake but it always best to be careful so that type of thing isn't done even accidentally. :)
Let me know if you have a question about this.
bol
Did you notice http:#20387106 ? Your post copies the contents of mine. Please either give credit or read previous comments more carefully. Hopefully it was just a mistake but it always best to be careful so that type of thing isn't done even accidentally. :)
Let me know if you have a question about this.
bol
ASKER
i don ;t know where i got wrong with explaining my question but i will try again:)
i need that inside the input text user will be able to insert only numbers 0-9, nothing else.
yes it have to be 10...but this i will do with maxlenght...
onKeyUp="if (isNaN(this.value)) this.value=this.value.repl ace(/[^0-9 ]/g,'')
this not good cause it premit the user to write point between the numbers like it be a price...than its not good
i need that inside the input text user will be able to insert only numbers 0-9, nothing else.
yes it have to be 10...but this i will do with maxlenght...
onKeyUp="if (isNaN(this.value)) this.value=this.value.repl
this not good cause it premit the user to write point between the numbers like it be a price...than its not good
The problem is the isNaN. use ...
<input type="text" onkeypress="var k = (e.which)? e.which : e.keyCode; return (k < 48 || k > 57) ? false : return true;">
That should do it. Sorry for overlooking the isNaN.
bol
<input type="text" onkeypress="var k = (e.which)? e.which : e.keyCode; return (k < 48 || k > 57) ? false : return true;">
That should do it. Sorry for overlooking the isNaN.
bol
ASKER
this not working at all
http://ilmc.brinkster.net/comersus/crm/amigos.asp
http://ilmc.brinkster.net/comersus/crm/amigos.asp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You mean
<input type="text" onkeypress="var k = (e.which)? e.which : e.keyCode; return (k < 48 || k > 57) ? false : true;">
or
<input type="text" onkeypress="var k = (e.which)? e.which : e.keyCode; return !(k < 48 || k > 57) ">
or
<input type="text" onKeyUp="this.value=this.v alue.repla ce(/[^0-9] /g,'')">
<input type="text" onkeypress="var k = (e.which)? e.which : e.keyCode; return (k < 48 || k > 57) ? false : true;">
or
<input type="text" onkeypress="var k = (e.which)? e.which : e.keyCode; return !(k < 48 || k > 57) ">
or
<input type="text" onKeyUp="this.value=this.v
Oh, You fixed it
ASKER
sorry, what?:)
Thanks for the grade, the points and the fun question.
bol
p.s. mplungjan, Yeah, I caught that error and also had to change the code so e was actually defined. The script is usually in a function but I knew Sasha85 wanted it short as possible and probably inline. Thanks for posting. :)
bol
p.s. mplungjan, Yeah, I caught that error and also had to change the code so e was actually defined. The script is usually in a function but I knew Sasha85 wanted it short as possible and probably inline. Thanks for posting. :)
https://www.experts-exchange.com/questions/22970039/only-numbers-allowed.html