Javascript UDF Overview

Source: Internet
Author: User
/***** Remove the string header and tail string *****/
Function strtrim (STR ){
VaR pattern =/(^/S +) $/; STR = Str. Replace (pattern ,"");
VaR pattern =/(/S +) $/; STR = Str. Replace (pattern ,"");
Return STR;
}

/***** Single-choice button detection *****/

Function check_radio (check_radio)
{
For (I = 0; I if (check_radio [I]. checked = true) {return true;} return false;}/***** whether it is a single number of characters (0 ~ 9) *****/function isnumber (STR) {If (/^/d $/g ). test (STR) = true) return true; return false ;}

/***** Whether it is an integer *****/

function isInteger(str){    if (/^/d+$/.test(str) == true) {        return true;    }    return false;    }

/***** Normal pop-up window *****/

Function openwin (URL, width, height, top, left, winscroll) {window. open (URL, "_ blank", 'width = '+ width +', Height = '+ height +', Top = '+ TOP + ', left = '+ Left +', resizable = No, status = No, scrollbars = '+ winscroll +', toolbar = No, menubar = No, location = no ')} /***** show the mode-free dialog box *****/function showdialog (URL, width, height, dialogscroll) {var arr = showmodaldialog (URL, window, "dialogwidth: "+ width +" PX; dialogheight: "+ Height +" PX; center: Yes; help: No; resizable: No; Status: No; scroll: "+ dialogscroll + "");} /***** check the validity of the IP address *****/function isvalidip (STR) {STR = strtrim (STR); temp = Str. split ('. '); If (temp. length! = 4) {return false;} else {for (I = 0; I if ((! Isinteger (temp [I]) | (temp [I] <0) | (temp [I]> 255) {return false ;}} return true ;} /***** check the validity of the email address *****/function checkemail (email) {var filter =/^/W + (-/W +) | (/. /W +) */@ [A-Za-z0-9] + ((/. |-) [A-Za-z0-9] + )*/. [A-Za-z0-9] + $/; Return (New Regexp (filter ). test (email);}/***** check the validity of the ID card *****/function isvalididcard (s) {S = strtrim (s); If (S. length = 15) {for (I = 0; I if (! (Isnumber (S. charat (I) {return false;} return true;} else if (S. length = 18) {for (I = 0; I if (! (Isnumber (S. charat (I) {return false;} return true;} return false}

 

 

/***** Determines whether the Chinese function is ***/function ischinese (s) {var ret = true; For (VAR I = 0; iret = RET & (S. charcodeat (I)> = 10000); return ret;}/***** number judgment function *****/function isnumber (s) {var digits = "0123456789"; var I = 0; var slength = S. length; while (I <slength) {var c = S. charat (I); If (digits. indexof (c) =-1) return false; I ++;} return true ;}

 

/***** Mask all keyboard keys *****/function document. onkeydown () {event. keycode = 0; event. returnvalue = false;}/***** right-click *****/function document. oncontextmenu () {return false;}/***** block Ctrl + N, Shift + F10, F5 refresh, Return key *****/function window. onhelp () {return false} // block the F1 help function keydown () {If (window. event. altkey) & (window. event. keycode = 37) | // mask Alt + direction key trim (window. event. keycode = 39) {// mask Alt + direction keys → alert ("You are not allowed to use Al T + direction key forward or backward webpage! "); Event. returnvalue = false;}/* Note: this does not really block Alt + direction keys, because when the Alt + direction keys pop up the warning box, hold down the Alt key and drop the warning box with the mouse, this blocking method becomes invalid. In the future, if any expert has a method to block the Alt key, please let us know. */If (event. keycode = 8) & (event. srcelement. type! = "Text" & event. srcelement. type! = "Textarea" & event. srcelement. type! = "Password") | // block the unsigned deletion key (event. keycode = 116) | // block the F5 refresh key (event. ctrlkey & event. keycode = 82) {// Ctrl + revent. keycode = 0; event. returnvalue = false;} If (event. ctrlkey) & (event. keycode = 78) // block Ctrl + nevent. returnvalue = false; If (event. shiftkey) & (event. keycode = 121) // block SHIFT + f10event. returnvalue = false; If (window. event. srcelement. tagname = "A" & window. event. shiftkey) window. event. returnval UE = false; // block shift with the left mouse button to open a new page if (window. event. altkey) & (window. event. keycode = 115) {// block Alt + f4window. showmodelessdialog ("about: blank", "", "dialogwidth: 1px; dialogheight: 1px"); Return false ;}} /***** shield the browser from "minimizing", "maximizing", and "disabling" the key *****/function window. onbeforeunload () {If (event. clientx> document. body. clientwidth & event. clienty <0 | event. altkey) {window. event. returnvalue = "" ;}}/***** block the F5 key *****/function docum Ent. onkeydown () {If (event. keycode = 116) {event. keycode = 0; event. cancelbubble = true; return false ;}}/***** form items cannot be empty *****/function checkform () {If (document. form. name. value. length = 0) {alert ("enter your name! "); Document. form. name. focus (); Return false;} return true;}/***** compare whether the values of the two form items are the same *****/function checkform () if (document. form. PWD. value! = Document. Form. pwd_again.value) {alert ("the password you entered twice is different! Enter again. "); document. adduser. PWD. focus (); Return false;} return true;}/***** form items can only be numbers and "_", used for phone/bank account verification, */function isnumber (string) {var letters = "1234567890-"; // you can add the input var I and VAR C values; if (string. charat (0) = '-') return false; If (string. charat (string. length-1) = '-') return false; for (I = 0; I <string. length; I ++) {c = string. charat (I); If (letters. indexof (c) <0) return false;} retur N true;} function checkform () {If (! Isnumber (document. Form. Tel. Value) {alert ("your phone number is invalid! "); Document. form. tel. focus (); Return false;} return true;}/***** form item input value/length limit *****/function checkform () {If (document. form. count. value> 100 | document. form. count. value <1) {alert ("the input value cannot be less than zero or greater than 100! "); Document. Form. Count. Focus (); Return false;} If (document. Form. Message. value. Length <10) {alert (" the input text is less than 10! "); Document. form. message. focus (); Return false;} return true;}/***** Determination of Chinese/English/numbers/mail address legality *****/function isenglish (name) // english value detection {If (name. length = 0) return false; for (I = 0; I <name. length; I ++) {If (name. charcodeat (I)> 128) return false;} return true;} function ischinese (name) // Chinese value detection {If (name. length = 0) return false; for (I = 0; I <name. length; I ++) {If (name. charcodeat (I)> 128) return true;} return false;} f Unction Ismail (name) // E-mail value detection {If (! Isenglish (name) return false; I = Name. indexof ("@"); j = Name. lastindexof ("@"); if (I =-1) return false; if (I! = J) return false; if (I = Name. length) return false; return true;} function isnumber (name) // value detection {If (name. length = 0) return false; for (I = 0; I <name. length; I ++) {If (name. charat (I) <"0" | Name. charat (I)> "9") return false;} return true;} function checkform () {If (! Ismail (Form. Email. Value) {alert ("your email is invalid! "); Form. Email. Focus (); Return false;} If (! Isenglish (Form. Name. Value) {alert ("the English name is invalid! "); Form. Name. Focus (); Return false;} If (! Ischinese (Form. cnname. Value) {alert ("the Chinese name is invalid! "); Form. cnname. Focus (); Return false;} If (! Isnumber (Form. publiczipcode. Value) {alert ("the zip code is invalid! "); Form. publiczipcode. focus (); Return false;} return true;}/***** specifies the characters that cannot be entered by Form Items *****/function contain (STR, charset) // string contains the test function {var I; for (I = 0; I <charset. length; I ++) if (Str. indexof (charset. charat (I)> = 0) return true; return false;} function checkform () {If (contain (document. form. name. value, "%/(/)> <") | (contain (document. form. message. value, "%/(/)> <") {alert ("illegal character entered"); document. form. name. focus (); Return false;} return true ;}

 

 

/***** Check the mobile phone number *****/function checkmobile (mobile) {var filter =/^ 13 [012356789] {1} [0-9] {8} $/; If (! Filter. test (mobile) return false; return true;}/***** check phone number *****/function checkphone (phone) {var arryphone = phone. split ("-") var Len = arryphone. length; // up to 2 "-" If (LEN> 3) return false; // All numbers for (var k = 0; k <Len; k ++) {If (arryphone [K]. replace (// D/GI ,"")! = "") Return false;} // "-" cannot be at the beginning of IF (LEN> 1) & (arryphone [0]. length <1) return false; return true;} function checkphone2 (phone) {var arryphone = phone. split ("-") var Len = arryphone. length; If (LEN> 3) return false; For (var k = 0; k <Len; k ++) {If (arryphone [K]. replace (// D/GI ,"")! = "") Return false;} If (LEN> 1) & (arryphone [0]. length <1) return false; If (LEN = 1) {If (! (Arryphone [0]. length> 6) & (arryphone [0]. length <9) return false;} If (LEN = 2) {If (arryphone [0]. length> 4) {If (! (Arryphone [0]. length> 6) & (arryphone [0]. length <9) return false; If (arryphone [1]. length> 4) return false;} else {If (arryphone [0]. length> 4) | (arryphone [0]. length <3) return false; If (! (Arryphone [1]. length> 6) & (arryphone [1]. length <9) return false ;}}if (LEN = 3) {If (arryphone [0]. length> 4) | (arryphone [0]. length <3) return false; If (! (Arryphone [1]. length> 6) & (arryphone [1]. length <9) return false; If (arryphone [2]. length> 4) return false;} return true;}/***** check email address *****/function checkemail (email) {var filter =/^/W + (-/W +) | (/. /W +) */@ [A-Za-z0-9] + ((/. |-) [A-Za-z0-9] + )*/. [A-Za-z0-9] + $/; Return (New Regexp (filter ). test (email ));
 
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.