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

📄 spryvalidationpassword.js

📁 ROYcms 是国内CMS市场的新秀、也是国内少有的采用微软的ASP.NET 2.0 + SQL2000/2005 技术框架开发的CMS
💻 JS
📖 第 1 页 / 共 2 页
字号:
		return this.invalidCharsMinClass;

	if (opt.maxChars !== false && this.input.value.length > opt.maxChars)
		return this.invalidCharsMaxClass;

	return true;
};
Spry.Widget.ValidationPassword.prototype.validateStrength = function(e)
{
	var opt = this.options;

	var value = this.input.value;
	if (opt.minAlphaChars !== false || opt.maxAlphaChars !== false)
	{
		var alphaChars = value.replace(/[^a-z]/ig, '').length;
		if ((opt.maxAlphaChars !== false && alphaChars > opt.maxAlphaChars) || (opt.minAlphaChars !== false && alphaChars < opt.minAlphaChars))
			return false;
	}
	if (opt.minUpperAlphaChars !== false || opt.maxUpperAlphaChars !== false)
	{
		var upperAlphaChars = value.replace(/[^A-Z]/g, '').length;
		if ((opt.maxUpperAlphaChars !== false && upperAlphaChars > opt.maxUpperAlphaChars) || (opt.minUpperAlphaChars !== false && upperAlphaChars < opt.minUpperAlphaChars))
			return false;
	}
	if (opt.minNumbers !== false || opt.maxNumbers !== false)
	{
		var numbers = value.replace(/[^0-9]/g, '').length;
		if ((opt.maxNumbers !== false && numbers > opt.maxNumbers) || (opt.minNumbers !== false && numbers < opt.minNumbers))
			return false;
	}
	if (opt.minSpecialChars !== false || opt.maxSpecialChars !== false)
	{
		var specials = value.replace(/[a-z0-9]/ig, '').length;
		if ((opt.maxSpecialChars !== false && specials > opt.maxSpecialChars) || (opt.minSpecialChars !== false && specials < opt.minSpecialChars))
			return false;
	}

	return true;
};

Spry.Widget.ValidationPassword.prototype.validate = function(e)
{
	var vLength = this.validateLength(e);
	if (vLength !== true)
	{
		this.switchClassName(this.element, vLength);
		this.switchClassName(this.additionalError, vLength);
		return false;
	}
	var vStrength = this.validateStrength(e);
	if (vStrength !== true)
	{
		this.switchClassName(this.element, this.invalidStrengthClass);
		this.switchClassName(this.additionalError, this.invalidStrengthClass);
		return false;
	}
	if (typeof this.options.validation == 'function')
	{
		var customValidation = this.options.validation(this.input.value, this.options);
		if (customValidation !== true)
		{
			this.switchClassName(this.element, this.invalidCustomClass);
			return false;
		}

	}
	this.switchClassName(this.element, this.validClass);
	this.switchClassName(this.additionalError, this.validClass);
	return true;
};

Spry.Widget.ValidationPassword.prototype.onBlur = function(e)
{
	this.removeClassName(this.element, this.focusClass);
	this.removeClassName(this.additionalError, this.focusClass);

	if (this.validateOn & Spry.Widget.ValidationPassword.ONBLUR)
		this.validate(e);
};
Spry.Widget.ValidationPassword.prototype.onFocus = function()
{
	this.addClassName(this.element, this.focusClass);
	this.addClassName(this.additionalError, this.focusClass);
};
Spry.Widget.ValidationPassword.prototype.switchClassName = function(ele, className)
{
	var classes = [this.validClass, this.requiredClass, this.invalidCharsMaxClass, this.invalidCharsMinClass, this.invalidStrengthClass, this.invalidCustomClass];
	for (var i =0; i< classes.length; i++)
		this.removeClassName(ele, classes[i]);

	this.addClassName(ele, className);
};
Spry.Widget.ValidationPassword.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.indexOf(className) != -1 && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};
Spry.Widget.ValidationPassword.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.indexOf(className) != -1 && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};
Spry.Widget.ValidationPassword.prototype.isBrowserSupported = function()
{
	return Spry.is.ie && Spry.is.v >= 5 && Spry.is.windows
		||
	Spry.is.mozilla && Spry.is.v >= 1.4
		||
	Spry.is.safari
		||
	Spry.is.opera && Spry.is.v >= 9;
};

Spry.Widget.ValidationPassword.prototype.isDisabled = function()
{
	return this.input && (this.input.disabled || this.input.readOnly) || !this.input;
};
Spry.Widget.ValidationPassword.prototype.showError = function(msg)
{
	alert('Spry.ValidationPassword ERR: ' + msg);
};

//////////////////////////////////////////////////////////////////////
//
// Spry.Widget.Form - common for all widgets
//
//////////////////////////////////////////////////////////////////////

if (!Spry.Widget.Form) Spry.Widget.Form = {};
if (!Spry.Widget.Form.onSubmitWidgetQueue) Spry.Widget.Form.onSubmitWidgetQueue = [];

if (!Spry.Widget.Form.validate)
{
	Spry.Widget.Form.validate = function(vform)
	{
		var isValid = true;
		var isElementValid = true;
		var q = Spry.Widget.Form.onSubmitWidgetQueue;
		var qlen = q.length;
		for (var i = 0; i < qlen; i++)
			if (!q[i].isDisabled() && q[i].form == vform)
			{
				isElementValid = q[i].validate();
				isValid = isElementValid && isValid;
			}
		return isValid;
	};
};

if (!Spry.Widget.Form.onSubmit)
{
	Spry.Widget.Form.onSubmit = function(e, form)
	{
		if (Spry.Widget.Form.validate(form) == false)
			return false;
		return true;
	};
};

if (!Spry.Widget.Form.onReset)
{
	Spry.Widget.Form.onReset = function(e, vform)
	{
		var q = Spry.Widget.Form.onSubmitWidgetQueue;
		var qlen = q.length;
		for (var i = 0; i < qlen; i++)
			if (!q[i].isDisabled() && q[i].form == vform && typeof(q[i].reset) == 'function')
				q[i].reset();
		return true;
	};
};

if (!Spry.Widget.Form.destroy)
{
	Spry.Widget.Form.destroy = function(form)
	{
		var q = Spry.Widget.Form.onSubmitWidgetQueue;
		for (var i = 0; i < Spry.Widget.Form.onSubmitWidgetQueue.length; i++)
			if (q[i].form == form && typeof(q[i].destroy) == 'function')
			{
				q[i].destroy();
				i--;
			}
	}
};

if (!Spry.Widget.Form.destroyAll)
{
	Spry.Widget.Form.destroyAll = function()
	{
		var q = Spry.Widget.Form.onSubmitWidgetQueue;
		for (var i = 0; i < Spry.Widget.Form.onSubmitWidgetQueue.length; i++)
			if (typeof(q[i].destroy) == 'function')
			{
				q[i].destroy();
				i--;
			}
	}
};

//////////////////////////////////////////////////////////////////////
//
// Spry.Widget.Utils
//
//////////////////////////////////////////////////////////////////////

if (!Spry.Widget.Utils)	Spry.Widget.Utils = {};
Spry.Widget.Utils.setOptions = function(obj, optionsObj, ignoreUndefinedProps)
{
	if (!optionsObj)
		return;
	for (var optionName in optionsObj)
	{
		if (ignoreUndefinedProps && optionsObj[optionName] == undefined)
			continue;
		obj[optionName] = optionsObj[optionName];
	}
};

Spry.Widget.Utils.firstValid = function()
{
	var ret = null;
	for(var i=0; i<Spry.Widget.Utils.firstValid.arguments.length; i++)
		if (typeof Spry.Widget.Utils.firstValid.arguments[i] != 'undefined')
		{
			ret = Spry.Widget.Utils.firstValid.arguments[i];
			break;
		}
	return ret;
};

Spry.Widget.Utils.getOptionRealValue = function(option, alternate)
{
	var value = Spry.Widget.Utils.firstValid(option, alternate);
	if (value !== false)
		value = parseInt(value, 10);

	if (isNaN(value) || value < 0)
		value = false;

	return value;
};

Spry.Widget.Utils.getValidChildrenWithNodeNameAtAnyLevel = function(node, nodeName, type)
{
	var elements  = node.getElementsByTagName(nodeName);
	var to_return = [];
	var j=0;
	if (elements)
	{
		for (var i=0; i < elements.length; i++)
			if (typeof elements[i].type != 'undefined' && elements[i].type.toUpperCase() == type.toUpperCase())
			{
				to_return[j] = elements[i];
				j++;
			}
	}
	return to_return;
};
Spry.Widget.Utils.getFirstParentWithNodeName = function(node, nodeName)
{
	while (node.parentNode
			&& node.parentNode.nodeName.toLowerCase() != nodeName.toLowerCase()
			&& node.parentNode.nodeName != 'BODY')
		node = node.parentNode;


	if (node.parentNode && node.parentNode.nodeName.toLowerCase() == nodeName.toLowerCase())
		return node.parentNode;
	else
		return null;
};
Spry.Widget.Utils.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)
			element.addEventListener(eventType, handler, capture);
		else if (element.attachEvent)
			element.attachEvent("on" + eventType, handler, capture);
	}
	catch (e) {}
};

Spry.Widget.Utils.removeEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.removeEventListener)
			element.removeEventListener(eventType, handler, capture);
		else if (element.detachEvent)
			element.detachEvent("on" + eventType, handler, capture);
	}
	catch (e) {}
};

⌨️ 快捷键说明

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