In C/S and B/S, how does one verify the value entered by the user on the keyboard?

Source: Internet
Author: User

 

In C/S

In the WinForm program, if you want to allow a text box to only enter numbers or letters, you can only enter the following methods ('\ B means: Delete the key ungemb '):

 

Only letters can be entered

Private void textBox2_KeyPress (object sender, KeyPressEventArgs e)

{

// Whether to process the event. If it is true, the event will be processed; otherwise, the event will not be processed.

E. Handled = true;

If (e. keyChar> = 'A' | e. keyChar> = 'A') & (e. keyChar <= 'Z' | e. keyChar <= 'Z') | e. keyChar = '\ B ')

{

E. Handled = false;

}

}

Only numbers can be entered

Private void textBox1_KeyPress (object sender, KeyPressEventArgs e)

{

E. Handled = true;

If (e. KeyChar> = '0' & e. KeyChar <= '9' | e. KeyChar = '\ B ')

{

E. Handled = false;

}

 

}

 

 

Method for rewriting in WINFORM: ProcessCmdKey can obtain keyboard keys

Protected override bool ProcessCmdKey (ref Message msg, Keys keyData)

{

Const int WM_KEYDOWN = 0X100;

Const int WM_SYSKEYDOWN = 0X104;

String strInfo = string. Empty;

 

If (msg. Msg = WM_KEYDOWN) | (msg. Msg = WM_SYSKEYDOWN ))

{

Switch (keyData)

{

Case Keys. Down:

StrInfo = "down ";

Break;

Case Keys. Up:

StrInfo = "up ";

Break;

Case Keys. Left:

StrInfo = "Left ";

Break;

Case Keys. Right:

StrInfo = "right ";

Break;

}

}

Return base. ProcessCmdKey (ref msg, keyData );

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In B/S

In. aspx, you can only enter numbers as follows:

1. Verify using the JS method

2. Use Keyboard Events (also JS)

<Input onkeypress = "if (event. keyCode> = 48 & event. keyCode <= 57) {event. returnValue = true;} else {event. returnValue = false;} "/>

 

 

In. aspx, you can only enter letters as follows:

1. Verify using the JS method

2. Use Keyboard Events (uppercase letters: 65-90, lowercase letters: 97-122)

<Input onkeypress = "if (event. keyCode> = 65 & event. keyCode <= 90) | (event. keyCode> = 97 & event. keyCode <= 122) {event. returnValue = true;} else {event. keyCode = false;} "/>

 

 

Input Method of the shielded text box: style = "ime-mode: disabled"

 

 

How to remove the dotted line on the button when the button is pressed: hidefocus = "false"

 

 

From happy pig's column

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.