Practical development tips for Windows Phone (15): Allow only numbers to be entered in the input box

Source: Internet
Author: User

On other platforms, whether it is winform, WPF, Silverlight, or ASP. NET, you may encounter the following requirement: You can only enter numbers in the input box. In fact, the implementation methods are similar. Obtain the key of the input text and determine whether it is a usable range. The following describes how to allow the input box to only enter numbers in Windows Phone.

We know that we can set the inputscope in the input box. When the input box gets the focus, different SIP messages are displayed. In wnidows phone, there are two inputscope types that can pop up the sip of the input number:

Number and telephonenumber:

The keys corresponding to the numbers in the two types of SIP are also different:

The 0-9 platformkeycode of inputscope is 48-57 (hexadecimal is 0x30-0x39), and the key is the D0-D9;

Inputscope is telephonenumber 0-9 platformkeycode is 96-105 (hexadecimal is 0x60-0x69), key is NumPad0-NumPad9.

Note that in the SIP with inputscope as number, @ and 2, # And 3, $ and 4...) and 9 share a key.Therefore, we do not recommend that you use the sip with inputscope as the number-only inputscope.

 

Summary: in Windows Phone, you can only enter numbers in the input box:

1. Set inputscope in the input box to telephonenumber.

2. register the keydown event in the input box and make the above judgment in the event

Source codeDownload:

 

Update: InIn mango, The inputscope of number is added. Set inputscope to number.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.