匹配IPfunction isIP1(strIP) { if (strIP == ""){ return false}; var strRegex= /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[09][0-9]|[1-9][0-9]|[0-9]|\*)$/ //匹配IP地址的正则表达式 if(strRegex.test(strIP)){ return true;} return false; }
//返回val的字节长度(中文算两个字节) function getByteLen(val) { var len = 0; for ( var i = 0; i < val.length; i++) { if (val[i].match(/[^\x00-\xff]/ig) != null) //全角 len += 2; else len += 1; } return len;}
验证URLvar strRegex = "^((https|http)://)?[a-z0-9A-Z]{3}\.[a-z0-9A-Z][a-z0-9A-Z]{0,61}?[a-z0-9A-Z]\.com|net|cn|cc (:s[0-9]{1-4})?/$"; var re = new RegExp(strRegex);re.test(str)