[英]Restrict TextBoxField to accept only numeric values in BlackBerry
How can I restrict a TextBoxField in BlackBerry to accept only numeric values . 如何限制BlackBerry中的TextBoxField仅接受数字值。 I'm new to BB world and would like to know if there is any control like a NumericTextbox in asp.net that I can use with BB? 我是BB世界的新手,想知道asp.net中是否有可以与BB一起使用的控件,例如NumericTextbox? Also from what I read through some blogs and documents , regex is not supported in BB. 另外,根据我从一些博客和文档中读到的内容,BB不支持正则表达式。 So how can I achieve this without Regex? 那么,没有Regex怎么实现呢?
Thanks in advance 提前致谢
Use a BasicEditField , or any of it's subclasses, include the FILTER_NUMERIC in the style parameter of the constructor: 使用BasicEditField或其任何子类,在构造函数的style参数中包括FILTER_NUMERIC :
BasicEditField numericField = new BasicEditField(FILTER_NUMERIC);
For more on using text filters see this article . 有关使用文本过滤器的更多信息,请参见本文 。
You can check this in javascript 您可以在javascript中检查
<script language=Javascript>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<html>
<body>
<form action="url" method="get/post">
<input id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.