View Full Version : Two simple questions!
Hitman
15-12-2007, 04:45 PM
Hey, two really quick simple questions!
1) For SQL, what type to you put it as so only numbers can be in it not text?
2) What do you put so on an HTML form the input can only be numbers?
Two simple questions, I don't know my head kills. :P
Florx
15-12-2007, 04:46 PM
1) INT
2) Use javascript
EDIT:
Just did a quick google and got:
function numbersonly(e) {
var unicode=e.charCode? e.charCode : e.keyCode;
if (unicode!=8){ //if the key isn’t the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number return false
//disable key press
}}
Usage:
<input onkeypress=”return numbersonly(event);” name=”NAME”>
REMEMBER http://jake-hall.co.uk/images/googleitnoob.gif
Hitman
15-12-2007, 04:54 PM
1) Thanks
2) I did http://jake-hall.co.uk/images/googleitnoob.gif :P xD
But isn't there an option to do it in html?
Invent
15-12-2007, 04:56 PM
No there isn't :P
Florx
15-12-2007, 04:57 PM
Well I google'd "JavaScript Numeric Only Input".
Hitman
15-12-2007, 04:58 PM
I was thinking, I should know if there is...
I don't want to use javascript in it, ah, I'll just make sure whoever inputs anything in it makes sure it's a number.
(It's not going to effect any security, it's just the value of the credit code :P)
Edit: Ah good, it can be done with PHP.
if (!is_numeric($_POST['amount'])) {
echo "The amount you entered wasn't a number.";
}
Mentor
15-12-2007, 06:16 PM
I was thinking, I should know if there is...
I don't want to use javascript in it, ah, I'll just make sure whoever inputs anything in it makes sure it's a number.
(It's not going to effect any security, it's just the value of the credit code :P)
Edit: Ah good, it can be done with PHP.
if (!is_numeric($_POST['amount'])) {
echo "The amount you entered wasn't a number.";
}
No it cant? what you just did was completely different from what you asked people to do?
You asked if it were possible to stop anyone entering none numeric text in to a text box... there was using Js.
What you just did is check whether an input is numeric. This has no effect on whether text can be entered in to the textbox o.0
Hitman
16-12-2007, 02:00 PM
No it cant? what you just did was completely different from what you asked people to do?
You asked if it were possible to stop anyone entering none numeric text in to a text box... there was using Js.
What you just did is check whether an input is numeric. This has no effect on whether text can be entered in to the textbox o.0
Yes, you're right, sorry.
What I posted will check if it's a number, if it's not it echos that it wasn't a number and wont input into the DB.
I wanted so only numbers can be inputted, but if I had been given this aswell I wouldn't have minded, so yes I worded it wrong as well in a way.
The matter is closed now, (the thread can be left open) because I have something similar to what I intentionally needed.
you could actually use php and js, but js would be easier on its own
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.