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