By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,628 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,628 IT Pros & Developers. It's quick & easy.

Numeric Text

P: n/a
Hello all,

Is there any way makes me prevent the user from entering characters in
a Text object
I want the Textbox to accept only numeric values when writting into it.

Thanks

Regards,

Dec 8 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
lightzizo wrote:
Is there any way makes me prevent the user from entering characters in
a Text object
1. There is no Text object. You probably mean an input[type="text"]
element.

2. No, client-side script support may be not present, so do not bother.
You need to validate this server-side anyway.
I want the Textbox to accept only numeric values when writting into it.


Google is your friend. [psf 6.1]

<URL:http://jibbering.com/faq/>
PointedEars
Dec 8 '05 #2

P: n/a
lightzizo wrote:
Is there any way makes me prevent the user from entering characters in
a Text object
I want the Textbox to accept only numeric values when writting into
it.


This might help:

<script type="text/javascript">
function filter(e) {
var ascii;
if (e && e.charCode) {
ascii = e.charCode;
} else if (event && event.keyCode) {
ascii = event.keyCode;
} else {
return true;
}

if (ascii < 48 || ascii > 57) return false;
return true;
}

window.onload = function () {
document.forms[0].elements['test'].onkeypress = filter;
document.forms[0].elements['test'].onpaste =
function () {
return false;
}
}
</script>
.....
<form>
<input type="text" name="test" />
</form>
JW
Dec 8 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.