/* var v = new Validator(); var val = v.verURL(str,type,pref,prefArr); var str = v.str - get string str - String variable; ptef: true - with (http://|https://) false - without (http://|https://) type: 0 - www.mail.ru 1 - www.mail.ru(:port) 2 - www.mail.ru/(string param) 3 - www.mail.ru(:port)/(string param) 4 - www.mail.ru:port 5 - www.mail.ru:port/(string param) prefArr - not necessarily ( var prefArr = new Array(); prefArr.push("ftp://"); ) var v = new Validator(); var val = v.verMAIL(str, dnsArr); var str = v.str - get string str - String variable; prefArr - onli this domen, not necessarily ( var dnsArr = new Array(); dnsArr.push("mail.ru"); ) return value rtue or false */ function Validator() { this.verURL = f_validator_URL; this.verMAIL = f_validator_MAIL; this.verEmpty = f_validator_Empty; this.doGetDNS = f_validator_DNS; this.doGetCol = f_validator_Col; this.verChar = f_validator_CHAR; this.trimChar = f_validator_TRIM; this.trimCharR = f_validator_TRIM_R; this.trimCharL = f_validator_TRIM_L; this.verFolder = f_validator_FOLDER; this.verPath = f_validator_PATH; this.str = ""; } function f_validator_CHAR(str) { var val = false; for(var i=0; i32&&ch<147) { } else { val = true; } } return val; } function f_validator_FOLDER(str) { var val = false; if(/\?/.test(str)) { var temp = ""; var temp1 = ""; for(var i = 0; i|\^|\||\"|:|\.\./.test(temp)) val = true; if(/\/|\\|<|>|\^|\||\"|:|;|,| |#|\!|\[|\]|\{|\}|\(|\)|`|\+|\'/.test(temp1)) val = true; return val; } function f_validator_Empty(str) { var val = true; if(str != "undefined" && typeof str != "undefined") { if(str.length>0) val = false; } return val; } function f_validator_TRIM_L(str) { while(str.charCodeAt(0)==32) { str=str.substr(1,str.length-1); } return str; } function f_validator_TRIM_R(str) { while(str.charCodeAt(str.length-1)==32) { str=str.substr(0,str.length-1); } return str; } function f_validator_TRIM(str, type) { try { var cutType = parseInt(type); isNaN(cutType) && (cutType = 0); if(cutType>2 || cutType<0) cutType = 0; } catch(e) { var cutType = 0; } switch (cutType) { case 0: str = this.trimCharR(str); str = this.trimCharL(str); break; case 1: str = this.trimCharR(str); break; case 2: str = this.trimCharL(str); break; } return str; } function f_validator_DNS(str) { var strTemp = ""; var DNS = str.match(/^[a-zA-Z0-9\.\-]+/); if(DNS) { strTemp = DNS[0]; } return strTemp; } function f_validator_Col(str) { var val = 0; var arTemp = new Array(); arTemp = str.split("."); if(arTemp.length>1) { var test = true; for(var i=0; i(-1)) { } else { type = 0; } var val = false; switch (type) { case 0: if(!this.verEmpty(str)) { val = doURL0(str, pref, prefArray); } break; case 1: if(!this.verEmpty(str)) { val = doURL1(str, pref, prefArray); } break; case 2: if(!this.verEmpty(str)) { val = doURL2(str, pref, prefArray); } break; case 3: if(!this.verEmpty(str)) { val = doURL3(str, pref, prefArray); } break; case 4: if(!this.verEmpty(str)) { val = doURL4(str, pref, prefArray); } break; case 5: if(!this.verEmpty(str)) { val = doURL5(str, pref, prefArray); } break; } this.str = str; return val; function doPref(str, pref, prefArray) { val = false; if(pref) { var test = false; if(prefArray.length>0) { for(var i=0; i0)) val = true; } else { val = true; } return val; } function doClearPref(str, prefArray) { str = str.replace(/^http:\/\//i,""); str = str.replace(/^https:\/\//i,""); if(prefArray.length>0) { for(var i=0; i1&&port[0].length<6) val = port[0]; } return val; } function doURL0(str, pref, prefArray) { var val = false; if(doPref(str, pref, prefArray)) { str = doClearPref(str, prefArray); var dns = f_validator_DNS(str); var col = f_validator_Col(dns); if(col != 0) { var temp = str.replace(dns,""); if((temp.length==1&&temp=="/") || (temp=="")) { val = true; } } } return val; } function doURL1(str, pref, prefArray) { var val = false; if(doPref(str, pref, prefArray)) { str = doClearPref(str, prefArray); var dns = f_validator_DNS(str); var col = f_validator_Col(dns); if(col != 0) { var temp = str.replace(dns,""); var port = doGetPort(temp); temp = temp.replace(port,""); if((temp.length==1&&temp=="/") || (temp=="")) { val = true; } } } return val; } function doURL2(str, pref, prefArray) { var val = false; if(doPref(str, pref, prefArray)) { str = doClearPref(str, prefArray); var dns = f_validator_DNS(str); var col = f_validator_Col(dns); if(col != 0) { var temp = str.replace(dns,""); if(temp.length>0) { if(temp.substr(0,1)=="/") val = true; if(temp.substr(0,2)=="//") val = false; if(f_validator_FOLDER(temp)) val = false; if(f_validator_CHAR(temp)) val = false; } } } return val; } function doURL3(str, pref, prefArray) { var val = false; if(doPref(str, pref, prefArray)) { str = doClearPref(str, prefArray); var dns = f_validator_DNS(str); var col = f_validator_Col(dns); if(col != 0) { var temp = str.replace(dns,""); var port = doGetPort(temp); temp = temp.replace(port,""); if(temp.length>0) { if(temp.substr(0,1)=="/") val = true; if(f_validator_FOLDER(temp)) val = false; if(temp.substr(0,2)=="//") val = false; if(f_validator_CHAR(temp)) val = false; } else { val = true; } } } return val; } function doURL4(str, pref, prefArray) { var val = false; if(doPref(str, pref, prefArray)) { str = doClearPref(str, prefArray); var dns = f_validator_DNS(str); var col = f_validator_Col(dns); if(col != 0) { var temp = str.replace(dns,""); var port = doGetPort(temp); if(port != "") { temp = temp.replace(port,""); if((temp.length==1&&temp=="/") || (temp=="")) { val = true; } } } } return val; } function doURL5(str, pref, prefArray) { var val = false; if(doPref(str, pref, prefArray)) { str = doClearPref(str, prefArray); var dns = f_validator_DNS(str); var col = f_validator_Col(dns); if(col != 0) { var temp = str.replace(dns,""); var port = doGetPort(temp); if(port != "") { temp = temp.replace(port,""); if(temp.length>0) { if(temp.substr(0,1)=="/") val = true; if(temp.substr(0,2)=="//") val = false; if(f_validator_FOLDER(temp)) val = false; if(f_validator_CHAR(temp)) val = false; } else { val = true; } } } } return val; } } function f_validator_MAIL(str, dnsArray) { var val = false; str = this.trimChar(str); if(dnsArray=="undefined"||typeof dnsArray=="undefined") { var dnsArray = new Array(); } if(!this.verEmpty(str)) { val = doMail(str, dnsArray); } this.str = str; return val; function doGetName(str) { var val = ""; var name = str.match(/^[a-zA-Z0-9\.\-_]+@/); if(name) { if(name[0].substr(0,1) !="." && name[0].substr(name[0].length-2,2) !=".@") val = name[0]; } return val; } function doMail(str, dnsArray) { var val = false; var temp = str; var name = doGetName(str); temp = str.replace(name,""); var dns = f_validator_DNS(temp); temp = temp.replace(dns,""); var col = f_validator_Col(dns); if(dnsArray.length>0) { for(var i = 0; i