JavaScript fullwidth to halfwidth

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Script language = javascript>
// The fullwidth space is 12288, And the halfwidth space is 32.
// The Relationship Between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
// Document. write (65281 ). toString (16) + "----" + (65374 ). toString (16) + "----" + (12288 ). toString (16 ));
String. prototype. dbc2sbc = function ()
{
Return this. replace (/[\ uff01-\ uff5e]/g, function (a) {return String. fromCharCode (. charCodeAt (0)-65248 );}). replace (/\ u3000/g ,"");
}
Document. write ("ABC 123, we are all good friends". dbc2sbc ());
</Script>

Input control
HTML can only be entered in English
Copy codeThe Code is as follows:
<Input type = "text" onfocus = "this. style. imeMode = 'Disabled '"/>

Convert the fullwidth to halfwidth using JS (only numbers are allowed)
HTML
Copy codeThe Code is as follows:
<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"
>

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.