簡體   English   中英

限制TextBoxField在BlackBerry中僅接受數字值

[英]Restrict TextBoxField to accept only numeric values in BlackBerry

如何限制BlackBerry中的TextBoxField僅接受數字值。 我是BB世界的新手,想知道asp.net中是否有可以與BB一起使用的控件,例如NumericTextbox? 另外,根據我從一些博客和文檔中讀到的內容,BB不支持正則表達式。 那么,沒有Regex怎么實現呢?

提前致謝

使用BasicEditField或其任何子類,在構造函數的style參數中包括FILTER_NUMERIC

BasicEditField numericField = new BasicEditField(FILTER_NUMERIC);

有關使用文本過濾器的更多信息,請參見本文

您可以在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM