TextBox prohibit copy and paste and digit verification, decimal verification, Chinese Character verification, textbox decimal

Source: Internet
Author: User

TextBox prohibit copy and paste and digit verification, decimal verification, Chinese Character verification, textbox decimal

 

Verify Decimals

 

# Region verify decimals /// <summary> /// verify decimals /// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> private void txtRoomArea_KeyDown_ForFloat (object sender, keyEventArgs e) {TextBox txt = sender as TextBox; // you can only enter a decimal number if (e. key> = Key. numPad0 & e. key <= Key. numPad9) | e. key = Key. subtract | e. key = Key. decimal) {if (txt. text. contains (". ") & e. key = Key. decimal) {e. hand Led = true; return;} e. handled = false;} else if (e. key> = Key. d0 & e. key <= Key. d9) | e. key = Key. oemPeriod | e. key = Key. subtract) & e. keyboardDevice. modifiers! = ModifierKeys. shift) {if (txt. text. contains (". ") & e. key = Key. oemPeriod) {e. handled = true; return;} e. handled = false;} else {e. handled = true ;}# endregionVerify Decimals

 

TextBox Content Change Detection

 

# Region TextBox_TextChanged private void TextBox_TextChanged (object sender, TextChangedEventArgs e) {// mask Chinese Input and paste input TextBox = sender as textBox; TextChange [] change = new TextChange [e. changes. count]; e. changes. copyTo (change, 0); int offset = change [0]. offset; if (change [0]. addedLength> 0) {double num = 0; if (! Double. TryParse (textBox. Text, out num )&&! TextBox. text. equals ("-") {textBox. text = textBox. text. remove (offset, change [0]. addedLength); textBox. select (offset, 0) ;}/// NoteFieldConfigModel noteField = NoteFieldConfigs. first (t => t. ffieldName = textBox. name); // string value = string. isNullOrEmpty (textBox. text) = true? Null: textBox. text; // if (string. isNullOrEmpty (value) // {// return; //} // if (noteField. ffieldType = 3) // {// textBox. text = string. format ("{0: N2}", Convert. toDouble (value. trimStart (','); //} // if (noteField. ffieldType = 2 & (noteField. fimptClassID = null | noteField. fimptClassID = 0) // {// textBox. text = string. format ("{0: N0}", Convert. toDouble (value. trimStart (','); //} # endregionEvents when content changes

 

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.