简体   繁体   中英

Restrict TextBoxField to accept only numeric values in BlackBerry

How can I restrict a TextBoxField in BlackBerry to accept only numeric values . 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? Also from what I read through some blogs and documents , regex is not supported in BB. So how can I achieve this without 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 numericField = new BasicEditField(FILTER_NUMERIC);

For more on using text filters see this article .

You can check this in 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM