Summary of some restrictions on text boxes ~~

Source: Internet
Author: User

1. Chinese characters cannot be entered in the restricted text box:
In the past, we often used judgment to write data, for example:
Copy codeThe Code is as follows:
Function nocn (obj)
{
For (I = 0; I <document. getElementsByName ("Text1") [0]. value. length; I ++)
{
Var c = document. getElementsByName ("Text1") [0]. value. substr (I, 1 );
Var ts = escape (c );
If (ts. substring (0, 2) = "% u ")
{
Document. getElementsByName ("Text1") [0]. value = "";
Alert ("Chinese/fullwidth characters cannot be entered here ");
}
}
}


But few people use ime-mode: disabled (use css to disable text box input methods)
Ime-mode
Syntax:
Ime-mode: auto | active | inactive | disabled
Valid value:
Auto: default value. The IME status is not affected. Same as when the ime-mode attribute is not specified
Active: Specify all characters entered using IME. Activate the local language input method. You can still cancel IME activation.
Inactive: specifies all characters that do not use IME. Activate a non-local language. You can still cancel IME activation.
Disabled: Completely disable IME. For controls with focus (such as input boxes), you cannot activate IME.

So:
<Input onpaste = "return false;" type = "text" name = "textfield" style = "ime-mode: disabled" value = "">
Ime-mode: disabled indicates the disabled input method.
Extension:
Copy codeThe Code is as follows:
<Script language = "JavaScript">
<! --
Function change (oButton)
{
Var obj = document.all.txt;
If (obj. style. imeMode = "disabled ")
{
Obj. style. imeMode = "active ";
Obj. value = "";
OButton. value = "blocking Chinese Input Methods ";
}
Else
{
Obj. style. imeMode = "disabled ";
Obj. value = "";
OButton. value = "Activate Chinese Input Method ";
}
}
// -->
</SCRIPT>
<Input type = "text" NAME = "txt" style = "ime-mode: disabled" style = "ime-mode: disabled">
<Input type = "button" value = "Activate Chinese INPUT Method" onclick = "change (this)">

I think about it myself ~
2. The Restricted text box cannot be pasted:
We usually see this idea: Disable the Ctrl key and C key, and then disable the right-click function to disable the paste function perfectly.
So you need to write the JS file (this JS file has relevant content in this blog)
In fact, onpaste = "return false;" can be used perfectly to disable pasting. Note that the pasting function is disabled, so this attribute is used, even if you can't help but use the right-click function, you cannot paste the content.

So:
Copy codeThe Code is as follows:
<Input onpaste = "return false;" type = "text" name = "textfield" style = "ime-mode: disabled" value = "">

In onpaste, paste is disabled.

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.