⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sugar_3.js

📁 SugarCRM5.1 开源PHP客户关系管理系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
		return true;	}    // Check that we have numbers	myregexp = new RegExp(date_reg_format)	if(!myregexp.test(dtStr))		return false    m = '';    d = '';    y = '';    var dateParts = dtStr.match(date_reg_format);    for(key in date_reg_positions) {        index = date_reg_positions[key];        if(key == 'm') {           m = dateParts[index];        } else if(key == 'd') {           d = dateParts[index];        } else {           y = dateParts[index];        }    }    // Check that date is real    var dd = new Date(y,m,0);    // reject negative years    if (y < 1)        return false;    // reject month less than 1 and greater than 12    if (m > 12 || m < 1)        return false;    // reject days less than 1 or days not in month (e.g. February 30th)    if (d < 1 || d > dd.getDate())        return false;    return true;}function getDateObject(dtStr) {	if(dtStr.length== 0) {		return true;	}	myregexp = new RegExp(date_reg_format)	if(myregexp.exec(dtStr)) var dt = myregexp.exec(dtStr)	else return false;	var yr = dt[date_reg_positions['Y']];	var mh = dt[date_reg_positions['m']];	var dy = dt[date_reg_positions['d']];	var date1 = new Date();	date1.setFullYear(yr); // xxxx 4 char year	date1.setMonth(mh-1); // 0-11 Bug 4048: javascript Date obj months are 0-index	date1.setDate(dy); // 1-31	return date1;}function isBefore(value1, value2) {	var d1 = getDateObject(value1);	var d2 = getDateObject(value2);	return d2 >= d1;}function isValidEmail(emailStr) {	if(emailStr.length== 0) {		return true;	}	// cn: bug 7128, a period at the end of the string mangles checks. (switched to accept spaces and delimiters)	var lastChar = emailStr.charAt(emailStr.length - 1);	if(!lastChar.match(/[^\.]/i)) {		return false;	}	// mfh: bug 15010 - more practical implementation of RFC 2822 from http://www.regular-expressions.info/email.html, modifed to accept CAPITAL LETTERS	//if(!/[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/.test(emailStr))	//	return false	var emailArr = emailStr.split(/[,;]/);	for (var i = 0; i < emailArr.length; i++) {		if(!/^\s*[\w.%+\-]+@([A-Z0-9-]+\.)*[A-Z0-9-]+\.[A-Z]{2,4}\s*$/i.test(emailArr[i]) &&		   !/^[\w\s.%+\-]*<[A-Z0-9._%+\-]+?@([A-Z0-9-]+\.)*[A-Z0-9-]+\.[A-Z]{2,4}>\s*$/i.test(emailArr[i]))		   return false;	}	return true;}function isValidPhone(phoneStr) {	if(phoneStr.length== 0) {		return true;	}	if(!/^[0-9\-\(\)]+$/.test(phoneStr))		return false	return true}function isFloat(floatStr) {	if(floatStr.length== 0) {		return true;	}	if(!(typeof(num_grp_sep)=='undefined' || typeof(dec_sep)=='undefined'))		floatStr = unformatNumber(floatStr, num_grp_sep, dec_sep).toString();	return /^(-)?[0-9\.]+$/.test(floatStr);}function isDBName(str) {	if(str.length== 0) {		return true;	}	// must start with a letter	if(!/^[a-zA-Z][a-zA-Z\_0-9]+$/.test(str))		return false	return true}var time_reg_format = "[0-9]{1,2}\:[0-9]{2}";function isTime(timeStr) {	time_reg_format = time_reg_format.replace('([ap]m)', '');	time_reg_format = time_reg_format.replace('([AP]M)', '');	if(timeStr.length== 0){		return true;	}	//we now support multiple time formats	myregexp = new RegExp(time_reg_format)	if(!myregexp.test(timeStr))		return false	return true}function inRange(value, min, max) {	value = "" + value; // tyoung make sure we have a string before doing the replace	value = value.replace(/,/g,'.');  //CL - Fix for 16937	return value >= min && value <= max;}function bothExist(item1, item2) {	if(typeof item1 == 'undefined') { return false; }	if(typeof item2 == 'undefined') { return false; }	if((item1 == '' && item2 != '') || (item1 != '' && item2 == '') ) { return false; }	return true;}function trim(s) {	if(typeof(s) == 'undefined')		return s;	while (s.substring(0,1) == " ") {		s = s.substring(1, s.length);	}	while (s.substring(s.length-1, s.length) == ' ') {		s = s.substring(0,s.length-1);	}	return s;}function check_form(formname) {	if (typeof(siw) != 'undefined' && siw		&& typeof(siw.selectingSomething) != 'undefined' && siw.selectingSomething)			return false;	return validate_form(formname, '');}function add_error_style(formname, input, txt) {	inputHandle = eval("document." + formname + "['" + input + "']");	style = get_current_bgcolor(inputHandle);	if(inputHandle.parentNode.innerHTML.search(txt) == -1) {		errorTextNode = document.createElement('span');		errorTextNode.className = 'required';		errorTextNode.innerHTML = '<br />' + txt;		inputHandle.parentNode.appendChild(errorTextNode);	}	inputHandle.style.backgroundColor = "#FF0000";	inputsWithErrors.push(inputHandle);	for(wp = 1; wp <= 10; wp++) {		window.setTimeout('fade_error_style(style, ' + wp * 10 + ')', 1000 + (wp * 50));	}}/** * removes all error messages for the current form */function clear_all_errors() {    for(var wp = 0; wp < inputsWithErrors.length; wp++) {		if(typeof(inputsWithErrors[wp]) !='undefined' && typeof inputsWithErrors[wp].parentNode != 'undefined')			inputsWithErrors[wp].parentNode.removeChild(inputsWithErrors[wp].parentNode.lastChild);	}}function get_current_bgcolor(input) {	if(input.currentStyle) {// ie		style = input.currentStyle.backgroundColor;		return style.substring(1,7);	}	else {// moz		style = '';		styleRGB = document.defaultView.getComputedStyle(input, '').getPropertyValue("background-color");		comma = styleRGB.indexOf(',');		style += dec2hex(styleRGB.substring(4, comma));		commaPrevious = comma;		comma = styleRGB.indexOf(',', commaPrevious+1);		style += dec2hex(styleRGB.substring(commaPrevious+2, comma));		style += dec2hex(styleRGB.substring(comma+2, styleRGB.lastIndexOf(')')));		return style;	}}function hex2dec(hex){return(parseInt(hex,16));}var hexDigit=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");function dec2hex(dec){return(hexDigit[dec>>4]+hexDigit[dec&15]);}function fade_error_style(normalStyle, percent) {	errorStyle = 'c60c30';	var r1 = hex2dec(errorStyle.slice(0,2));	var g1 = hex2dec(errorStyle.slice(2,4));	var b1 = hex2dec(errorStyle.slice(4,6));	var r2 = hex2dec(normalStyle.slice(0,2));	var g2 = hex2dec(normalStyle.slice(2,4));	var b2 = hex2dec(normalStyle.slice(4,6));	var pc = percent / 100;	r= Math.floor(r1+(pc*(r2-r1)) + .5);	g= Math.floor(g1+(pc*(g2-g1)) + .5);	b= Math.floor(b1+(pc*(b2-b1)) + .5);	for(var wp = 0; wp < inputsWithErrors.length; wp++) {		inputsWithErrors[wp].style.backgroundColor = "#" + dec2hex(r) + dec2hex(g) + dec2hex(b);	}}function validate_form(formname, startsWith){    requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');    invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');	if ( typeof (formname) == 'undefined')	{		return false;	}	if ( typeof (validate[formname]) == 'undefined')	{		return true;	}	var form = "document." + formname;	var isError = false;	var errorMsg = "";	var _date = new Date();	if(_date.getTime() < (lastSubmitTime + 2000) && startsWith == oldStartsWith) { // ignore submits for the next 2 seconds		return false;	}	lastSubmitTime = _date.getTime();	oldStartsWith = startsWith;	clear_all_errors(); // remove previous error messages	inputsWithErrors = new Array();	for(var i = 0; i < validate[formname].length; i++){			if(validate[formname][i][nameIndex].indexOf(startsWith) == 0){				if(typeof eval(form + "['" + validate[formname][i][nameIndex] + "']" ) != 'undefined'){					var bail = false;					if(validate[formname][i][requiredIndex]){						if(typeof eval(form + "['" + validate[formname][i][nameIndex] + "']") == 'undefined' || trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")) == ""){							add_error_style(formname, validate[formname][i][nameIndex], requiredTxt +' ' + validate[formname][i][msgIndex]);							isError = true;						}					}					if(!bail){						switch(validate[formname][i][typeIndex]){						case 'email':							if(!isValidEmail(trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")))){								isError = true;								add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);							}							 break;						case 'time':							if( !isTime(trim(eval(form+"['" + validate[formname][i][nameIndex] + "']" + ".value")))){								isError = true;								add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);							} break;						case 'date': if(!isDate(trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")))){								isError = true;								add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);							}  break;						case 'alpha':							break;						case 'DBName':							if(!isDBName(trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")))){								isError = true;								add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);							}							break;						case 'alphanumeric':							break;						case 'int':							if(!isInteger(trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")))){								isError = true;								add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);							}							break;						case 'currency':						case 'float':							if(!isFloat(trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")))){								isError = true;								add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);							}							break;					    case 'error':							isError = true;                            add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);							break;						}						if(typeof validate[formname][i][jstypeIndex]  != 'undefined'/* && !isError*/){							switch(validate[formname][i][jstypeIndex]){							case 'range':								if(!inRange(trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value")), validate[formname][i][minIndex], validate[formname][i][maxIndex])){									isError = true;									add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " value " + eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value") + " is not within the valid range (" +validate[formname][i][minIndex] + " - " + validate[formname][i][maxIndex] +  ") ");								}							break;							case 'isbefore':								compareTo = form + "." + validate[formname][i][compareToIndex];								if(	typeof compareTo != 'undefined'){									if(trim(eval(compareTo + '.value')) != '' || (validate[formname][i][allowblank] != 'true') ) {										date2 = trim(eval(compareTo + '.value'));										date1 = trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value"));										if(trim(date1).length != 0 && !isBefore(date1,date2)){											isError = true;											//jc:#12287 - adding translation for the is not before message											add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + "(" + date1 + ") " + SUGAR.language.get('app_strings', 'MSG_IS_NOT_BEFORE') + ' ' +date2);										}									}								}							break;							case 'binarydep':								compareTo = form + "." + validate[formname][i][compareToIndex];								if( typeof compareTo != 'undefined') {									item1 = trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value"));									item2 = trim(eval(compareTo + '.value'));									if(!bothExist(item1, item2)) {										isError = true;										add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);									}								}							break;							case 'comparison':								compareTo = form + "." + validate[formname][i][compareToIndex];								if( typeof compareTo != 'undefined') {									item1 = trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value"));									item2 = trim(eval(compareTo + '.value'));									if(!bothExist(item1, item2) || item1 != item2) {										isError = true;										add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);									}								}							break;							case 'in_array':								arr = eval(validate[formname][i][arrIndex]);								operator = validate[formname][i][operatorIndex];								item1 = trim(eval(form + "['" + validate[formname][i][nameIndex] + "']" + ".value"));								for(j = 0; j < arr.length; j++){									val = arr[j];									if((operator == "==" && val == item1) || (operator == "!=" && val != item1)){										isError = true;										add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " +	validate[formname][i][msgIndex]);									}								}							break;							}						}					}				}			}		}/*	nsingh: BUG#15102	Check min max default field logic.	Can work with float values as well, but as of 10/8/07 decimal values in MB and studio don't have min and max value constraints.*/	if(formsWithFieldLogic){		var invalidLogic=false;		if(formsWithFieldLogic.min && formsWithFieldLogic.max && formsWithFieldLogic._default) {			var showErrorsOn={min:{value:'min', show:false, obj:formsWithFieldLogic.min.value},							max:{value:'max',show:false, obj:formsWithFieldLogic.max.value},							_default:{value:'default',show:false, obj:formsWithFieldLogic._default.value},							len:{value:'len', show:false, obj:parseInt(formsWithFieldLogic.len.value)}};			var min = (formsWithFieldLogic.min.value !='') ? parseInt(formsWithFieldLogic.min.value) : 'undef';			var max  = (formsWithFieldLogic.max.value !='') ? parseInt(formsWithFieldLogic.max.value) : 'undef';			var _default = (formsWithFieldLogic._default.value!='')? parseInt(formsWithFieldLogic._default.value) : 'undef';			/*Check all lengths are <= max size.*/			for(var i in showErrorsOn){				if(showErrorsOn[i].value!='len' && showErrorsOn[i].obj.length > showErrorsOn.len.obj){					invalidLogic=true;					showErrorsOn[i].show=true;					showErrorsOn.len.show=true;				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -