[Uwp Little White Diary-15] restrict the input of the textbox in real time on the UWP phone

Source: Internet
Author: User

Honestly, it never occurred to me that validating input is such a hard thing.Many online verification is done after the input is verified, my idea is to enter the time limit input, so I don't have to write code to verify theshould be the mobile phone side, so do not have to judge the other illegal characters, directly to the TextBox property InputScope set to "number" is, anyway, in the current version of the UWP in the pure numeric keyboard can not switch to the other character keyboard to The following code is a validation of an amount text box. Welcome and better advice! Directly on the code:
/// <summary>        ///Check the input amount and enter only 2 decimal places when the decimal is detected///You can only modify the value of a decimal when it is filled with 12 characters/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidValuetextbox_textchanged (Objectsender, Textchangedeventargs e) {            //if it is not empty            if(Valuetextbox.text! =string. Empty) {if(ValueTextBox.Text.Contains ('.'))                {                    if(ValueTextBox.Text.Count () = =Ten) {Valuetextbox.maxlength= ValueTextBox.Text.IndexOf ('.') +3; }                    Else{valuetextbox.maxlength= ValueTextBox.Text.IndexOf ('.') +3; }                }                Else                {                    //automatically complements the decimal place after the integer reaches 9 bits, and moves the cursor to the last                    if(ValueTextBox.Text.Count () = =9)                    {                        //Valuetextbox.text + = ". xx";Valuetextbox.maxlength =9; Valuetextbox.selectionstart=valueTextBox.Text.Length; }                }            }            Else            {                //The maximum number of characters for the Reset amount input box is nullValuetextbox.maxlength = A; }        }        /// <summary>        ///when the integer digit is 9 bits and the current input is a decimal point, set the TextBox maximum number of characters to 12, move the cursor to the last position/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidValuetextbox_keydown (Objectsender, Keyroutedeventargs e) {            //Do not know why and the default decimal point code is not the same, the default is            if(e.key.tostring () = =" the")            {                if(ValueTextBox.Text.Count () = =9) {Valuetextbox.maxlength= A; Valuetextbox.selectionstart=valueTextBox.Text.Length; }            }        }

It's too late, next time we make up the GIF.



From for notes (Wiz)



[Uwp Little White Diary-15] restrict the input of the textbox in real time on the UWP phone

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.