Verify the input in English only. If the input is English, true is returned. Otherwise, false is returned. If the input is English, true is returned. Otherwise, false is returned.
function isEnglish(name) { if(name.length == 0) return false; for(i = 0; i < name.length; i++) { if(name.charCodeAt(i) > 128) return false; } return true; }
// Verify the input in Chinese only. If the input is Chinese, true is returned. Otherwise, false is returned.
function isChinese(name) { if(name.length == 0) return false; for(i = 0; i < name.length; i++) { if(name.charCodeAt(i) > 128) return true; } return false; }
// Invalid character judgment. If 'str' contains charset, true is returned.
function contain(str,charset){ var i; for(i=0;i
=0){ return true; } return false; } }
// Select the text box or text field text, and add onClick/onFocus = "textSelect ();" to the input position. Then you can use the following code:
function textSelect() { var obj = document.activeElement; if(obj.tagName == "TEXTAREA") { obj.select(); } if(obj.tagName == "INPUT" ) { if(obj.type == "text") obj.select(); } }
// Only letters, numbers, and underscores are allowed.
function textOnly(){ var i= window.event.keyCode ; //8=backspace //9=tab //37=left arrow //39=right arrow //46=delete //48~57=0~9 //97~122=a~z //65~90=A~Z //95=_ if (!((i<=57 && i>=48)||(i>=97 && i<=122)||(i>=65 && i<=90)||(i==95)||(i==8)||(i==9)||(i==37)||(i==39)||(i==46))){ //window.event.keyCode=27; event.returnValue=false; return false; } else { //window.event.keyCode=keycode; return true; }}
// Determine the URL. true is returned for the correct URL; otherwise, false is returned.
function isURL(URL){ var urlPat=/^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/; var matchArray=URL.match(urlPat); if(matchArray!=null){ return true; } else { return false; } }
// Judge the short date (for example, 2003-5-23)
function isDate(date){ var r = date.match(/^(d{1,4})(-|/)(d{1,2})(d{1,2})$/); if(r==null){ return false; } if (r[1]<1 || r[3]<1 || r[3]-1>12 || r[4]<1 || r[4]>31) { return false } var d= new Date(r[1], r[3]-1, r[4]); if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]){ return true; } }
// Determine the short time (HH: MM: SS)
function isTime(time){ var a = time.match(/^(d{1,2})(:)?(d{1,2})(d{1,2})$/); if (a == null) { return false; } if (a[1]>23 || a[1]<0 || a[3]>60 || a[3]<0 || a[4]>60 || a[4]<0){ return false } return true; }
// In addition to the button in the form element, press the Enter key to simulate the TAB function.
function enterToTab(){ if (window.event.keyCode == 13 && window.event.ctrlKey == false && window.event.altKey == false){ if (window.event.srcElement.type != "button") window.event.keyCode = 9; } else { return true; } }
// When entering the form, press enter to submit the form. The name is the name of the sumbit control.
function enterTOSubmit(name) { if (window.event.keyCode == 13 && window.event.ctrlKey == false && window.event.altKey == false){ var objSubmit=document.getElementById(name); objSubmit.focus; } else { return true; } }
// Determines whether it is a floating point number. true is returned correctly.
function isFloat(float,index){ var floatPat=/^(d{1,})[.](d{1,})$/; var matchArray=float.match(floatPat); if(matchArray!=null) { if(matchArray[2].length==index){ return true; } } }
// Judge the maximum length of a character. If the length of strin is not greater than that of maxLen, true is returned.
function maxLength(strin,maxLen) { var len=0; for(var i=0;i
256) { len += 2; } else { len++; } } if(len<=maxLen){ return true; } }
// Judge the minimum length of a character. If the length is not smaller than minLen, true is returned.
function minLength(strin,minLen) { var len=0; for(var i=0;i
256) { len += 2; } else { len++; } } if(len>=maxLen){ return true; } }
// Consists of three functions: checkPassWord (), charMode (), bitTotal ()
// Verify the password complexity. The password consists of numbers, uppercase and lowercase letters, and any three combinations of special characters. true is returned if the password is passed.
Function checkPassWord (passWord, maxLen) {if (passWord. length <= maxLen) return false; // The passWord is too short. Modes = 0; for (I = 0; I
= 48 & iN <= 57) // number return 1; if (iN> = 65 & iN <= 90) // capital letter return 2; if (iN> = 97 & iN <= 122) // lower case return 4; else return 8; // special character} // bitTotal function // calculate the total number of modes in the current password: function bitTotal (num) {modes = 0; for (I = 0; I <4; I ++) {if (num & 1) modes ++; num >>>= 1 ;}if (modes = 3) {return true }}
// Determine whether the user name is valid. If the user name is valid, true is returned; otherwise, flase is returned.
// The username consists of letters, numbers, and underscores. It can only start with a letter and has a minimum length of 6 characters.
function isAccount(str){ if(/^[a-z]w{3,}$/i.test(str)) { return true; } else { return false; ] }
// Obtain the number of characters in the string
Function getChineseNum (obstring) {var pattern =/^ [1-marker] + $/I; var maxL, minL; maxL = obstring. length; obstring = obstring. replace (pattern, ""); minL = obstring. length; return (maxL-minL )}