Disable the ime-mode Input Method in JS and convert it to half-width

Source: Internet
Author: User

Style = "ime-mode: Disabled ;"

1. Use js to convert the fullwidth to halfwidth (punctuation cannot be converted)
<Input type = "text" size = "10" maxlength = "10"
Onkeyup = "javascript: var T =''; with (this. value) {for (VAR I = 0; I <length; I ++) T + = (65296 <= charcodeat (I) & charcodeat (I) <= 65305 )? String. fromcharcode (charcodeat (I)-65248): charat (I);} This. value = T ;"
/>
<Br>
<Br>
2. Use js to convert the fullwidth into a halfwidth Function
<Input name = "N" type = "text" id = "N" onkeyup = "ctoh (this);"/>
<SCRIPT>
Function ctoh (OBJ)
{
VaR STR = obj. value;
VaR result = "";
For (VAR I = 0; I <Str. length; I ++)
{
If (Str. charcodeat (I) = 12288)
{
Result + = string. fromcharcode (Str. charcodeat (I)-12256 );
Continue;
}
If (Str. charcodeat (I)> 65280 & Str. charcodeat (I) <65375)
Result + = string. fromcharcode (Str. charcodeat (I)-65248 );
Else result + = string. fromcharcode (Str. charcodeat (I ));
}
OBJ. value = result;
}
</SCRIPT>
<Br>
<Br>
3. Use js to convert the fullwidth to halfwidth (only numbers, decimal points, and negative numbers are allowed)
<Input
Onkeypress = "Var K = event. keycode; return K >=48 & K <= 57 | K = 46 | K = 45"
Onpaste = "return! ClipboardData. getdata ('text'). Match (/\ D /)"
Ondragenter = "Return false" style = "ime-mode: Disabled"
>
<Br>
<Br>
4. Convert the fullwidth to halfwidth using JS (only numbers are allowed)
<Input
Onkeypress = "Var K = event. keycode; return K >=48 & K <= 57"
Onpaste = "return! ClipboardData. getdata ('text'). Match (/\ D /)"
Ondragenter = "Return false" style = "ime-mode: Disabled"
>
<Br>
5. full-width characters are not allowed.
<Input name = "cardid" onkeyup = "quanjiao (this);">
<Script language = "JavaScript">
Function quanjiao (OBJ)
{
VaR STR = obj. value;
If (Str. length> 0)
{
For (VAR I = Str. Length-1; I> = 0; I --)
{
Unicode = Str. charcodeat (I );
If (UNICODE> 65280 & Unicode <65375)
{
Alert ("full-width characters are not allowed. Please enter half-width characters ");
OBJ. value = Str. substr (0, I );
}
}
}
}
</SCRIPT>

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.