Numeric/Decimals only...

I

IveCal

<PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="keyPress()"/>

<SCRIPT LANGUAGE="JScript">

function keyPress(){
if (!(window.event.keyCode >= 48 && window.event.keyCode <= 57) && !
(window.event.keyCode == 46)){
window.event.keyCode = 0;
}
}

</SCRIPT>

Hello... I'm new to HTC/JScript thing.
I have a textfield that uses the JScript behavior above.
(The JScript above only accepts 0-9 and .)
I want to customize my textfield such that only numbers/decimals can
be entered like:
2.45, 8.456 and 8. Not texts like "..5" or "." or "1.25..." or
"1..53." and the like.
Is that possible with JScript? Please do reply... Thanks a lot.
 
R

RobG

<PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="keyPress()"/>

<SCRIPT LANGUAGE="JScript">

function keyPress(){
if (!(window.event.keyCode >= 48 && window.event.keyCode <= 57) && !
(window.event.keyCode == 46)){
window.event.keyCode = 0;
}

}

</SCRIPT>

Hello... I'm new to HTC/JScript thing.
I have a textfield that uses the JScript behavior above.
(The JScript above only accepts 0-9 and .)
I want to customize my textfield such that only numbers/decimals can
be entered like:
2.45, 8.456 and 8. Not texts like "..5" or "." or "1.25..." or
"1..53." and the like.
Is that possible with JScript?

Yes. Forget using keycodes, use a regular expression:

<URL: http://www.merlyn.demon.co.uk/js-valid.htm#VNP >

Don't prevent any keystrokes, validate when the user has finished
using blur or change events.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top