0

Enable only numbers in textbox on user input?

asked 2011-07-06 04:53:25 +0800

Lesstra gravatar image Lesstra
193 1

Hi, I found this solution for HTML/JavaScript to disable real-time input of anything except numbers in text field:

<html>

<head>
<title></title>

<script language="javascript" type="text/javascript">
function numbersOnly (e)
{
    var keychar;
    var keynum;
    var numcheck;
    
    if(window.event) 		// IE
    { keynum = e.keyCode; }
    else if(e.which) 		// Netscape/Firefox/Opera
    { keynum = e.which; }
    
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    return numcheck.test(keychar);
}
</script>

</head>

<body>
<h2>Soem title</h2></br>
<input type="text" onkeypress="return numbersOnly(event)">
</input>
</body>

</html>

How should I implement this kind of (javascript) functionality for ZK Textbox element?
What client-side event should I be using...?

I read this link1 and this link2, but couldn't quite understand how to process types of client events with input arguments (f.e "onkeypress", assuming it exists in client namespace, because I don't know where to look for a list of available client-side events...)

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-07-06 04:59:07 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

Don't reinvent the wheel, use the already existing intbox:

<intbox value="42" constraint="no negative,no zero" />

Cheers, Maik

link publish delete flag offensive edit

answered 2011-07-06 05:13:35 +0800

Lesstra gravatar image Lesstra
193 1

updated 2011-07-06 05:16:50 +0800

Ok, thanks for the reply Maik :)

The title was obviously misleading, the idea behind the question was actually NOT about inputing only numbers in the text field,
but generaly about client side events with input arguments (like 'onkeypress', 'onkeydown'...).

For example, what if I want to input non-numbers only, or for that matter,
to apply any arbitrary constraint which should be validated on the fly (on user input)?

EDIT: I guess using jQuery is probably the solution, but I still can't find adequate examples

Thanks

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-07-06 04:53:25 +0800

Seen: 299 times

Last updated: Jul 06 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More