Solution 1: <Input onkeyup = "value = value. replace (/[\ uff00-\ Uffff]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ uff00-\ Uffff]/g, '')"> I am daring to comment: I cannot convert symbols such as ",", and the letter is incomplete... You need to be considerate or transformed. Solution 2: Halfwidth and fullwidth conversion functions [JS] [conversion] /* **************************** * Halfwidth <=> fullwidth * * [NB Alliance] * * Writer yuping * **************************** * Parameter description: * STR: string to be converted * Flag: flag. The flag is converted to full at half past zero. If the flag is not 0, it is switched to half. * Return value type: String **************************** */ Function dbc2sbc (STR, flag ){ VaR I; VaR result = '; If (Str. Length <= 0) {alert ('string parameter error'); Return false ;} For (I = 0; I <Str. length; I ++) {Str1 = Str. charcodeat (I ); If (str1 <125 &&! Flag) Result + = string. fromcharcode (Str. charcodeat (I) + 65248 ); Else Result + = string. fromcharcode (Str. charcodeat (I)-65248 ); } Return result; } // Example: Alert (dbc2sbc ("aaabc", 0 )); Document. Write (dbc2sbc ("abcdefg", 0 )) <Input type = text value = "abcdefg" id = TXT> <input type = button value = "" onclick = TXT. value = dbc2sbc (txt. Value)> I am brave enough to comment on it: The image is so flashy that everyone will be fond of it. Only letters can be converted. Funny and funny. Solution 3: <SCRIPT> VaR STR = "2003104345510defghighij9" VaR BSTR = "0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" VaR gstr = "0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" For (I = 0; I <Str. length; I ++) { BPOs = BSTR. indexof (Str. substr (I, 1 )) If (BPOs! =-1) { Bword = BSTR. substr (BPOs, 1) Gword = gstr. substr (BPOs, 1) STR = Str. Replace (New Regexp (bword, "G"), gword) } } Alert (STR) </SCRIPT> I am daring to comment: simple and effective. Also works. However, it takes time and effort to manually add a category. Solution 4: (ultimate solution) <SCRIPT> // Assign the character you think is fullwidth to the array str1, and then you can determine the fullwidth and halfwidth. VaR str1 = new array ("? "); VaR str2 = "ABC "; VaR Re =/[^ \ x00-\ X80] // or/[^ \ 0-\ 127]/decimal representation // [^ A-Z] matches within the specified range // Alert (str1.length ); For (VAR I = 0; I <str1.length; I ++) { If (Re. Test (str1 [I]) { Alert ("full-width character found, character:" + str1 [I]); }
} </SCRIPT> The aboveCodeVerification results can be achieved without listing them. Please verify... |