Unicode and character conversion using javascript

Source: Internet
Author: User

<Script language = "javascript">
// Mobile phone Detection
Function checkMobile (num ){
Reg =/^ 13 [0-9] \ d {8} $ /;
If (reg. test (num )){
Return true;
} Else {
Reg =/^ 15 [8-9] \ d {8} $ /;
If (reg. test (num )){
Return true;
} Else {
Reg =/^ 153 \ d {8} $ /;
If (reg. test (num )){
Return true;
} Else {
Return false;
}
}

}
}
</Script>
<Script language = "javascript">
// Convert unicode to character
Function unicode2Chr (str ){
If (''! = Str ){
Var st, t, I
St = '';
For (I = 1; I <= str. length/4; I ++ ){
T = str. slice (4 * I-4, 4 * I-2 );
T = str. slice (4 * I-2, 4 * I). concat (t );
St = st. concat ('% U'). concat (t );
}
St = unescape (st );
Return (st );
}
Else
Return ('');
}
// Convert character to unicode
Function chr2Unicode (str ){
If (''! = Str ){
Var st, t, I;
St = '';
For (I = 1; I <= str. length; I ++ ){
T = str. charCodeAt (I-1). toString (16 );
If (t. length <4)
While (t. length <4)
T = '0'. concat (t );
T = t. slice (2, 4). concat (t. slice (0, 2 ))
St = st. concat (t );
}
Return (st. toUpperCase ());
}
Else {
Return ('');
}
}

Var http_request = false;
Function getRequest (url ){
Http_request = false;
If (window. XMLHttpRequest) {// Mozilla, Safari ,...
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
Http_request.overrideMimeType ('text/xml ');
}
} Else if (window. ActiveXObject) {// IE
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Return false;
}
Http_request.onreadystatechange = showtlinfo;
Http_request.open ('get', url, true );
Http_request.send (null );
}

Function showtlinfo (){
If (http_request.readyState = 4 ){
If (http_request.status = 200 ){
Txt = http_request.responseText;
Document. noname = txt;
Document. all. noname. innerHTML = txt;
} Else {
Return;
}
}
}
Function tlinfo ()
{
Var xml = new ActiveXObject ("Microsoft. XMLDOM ");
Xml. async = "false ";
Xml. load ("http://my.x-push.net/xml/805128.xml ");
If (xml. parseError! = 0)
{
GetRequest ("http://my.x-push.net/getxml.asp? No = 805128 ");
Return;
}
Var root=xml.doc umentElement;
Txt = root. childNodes (1). text;
Document. noname = txt;
Document. all. noname. innerHTML = txt;
}
Tlinfo ();
</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.