Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
La biblioteca ECMAScript siguiente se emite al cliente y ofrece funciones para que las empleen los controles validadores que se muestran en Ejemplos de controles de validación. Esta biblioteca de secuencias de comandos se ajusta a la especificación del W3C (World Wide Web Consortium) de Document Object Model Level 1. Para obtener información general acerca de las secuencias de comandos de cliente en los controles de servidor, vea Funcionalidad de un control de servidor en el cliente.
// DomValidation.js.
//<script>
var Page_DomValidationVer = "2";
var Page_IsValid = true;
var Page_BlockSubmit = false;
function ValidatorUpdateDisplay(val) {
if (typeof(val.display) == "string") {
if (val.display == "None") {
return;
}
if (val.display == "Dynamic") {
val.style.display = val.isvalid ? "none" : "inline";
return;
}
}
val.style.visibility = val.isvalid ? "hidden" : "visible";
}
function ValidatorUpdateIsValid() {
var i;
for (i = 0; i < Page_Validators.length; i++) {
if (!Page_Validators[i].isvalid) {
Page_IsValid = false;
return;
}
}
Page_IsValid = true;
}
function ValidatorHookupControl(control, val) {
if (typeof(control.Validators) == "undefined") {
control.Validators = new Array;
var ev = control.onchange;
var func = new Function("ValidatorOnChange('" + control.id + "');");
control.onchange = func;
}
control.Validators[control.Validators.length] = val;
}
function ValidatorGetValue(id) {
var control;
control = document.getElementById(id);
if (typeof(control.value) == "string") {
return control.value;
}
if (typeof(control.tagName) == "undefined" && typeof(control.length) == "number") {
var j;
for (j=0; j < control.length; j++) {
var inner = control[j];
if (typeof(inner.value) == "string" && (inner.type != "radio" || inner.status == true)) {
return inner.value;
}
}
}
return "";
}
function Page_ClientValidate() {
var i;
for (i = 0; i < Page_Validators.length; i++) {
ValidatorValidate(Page_Validators[i]);
}
ValidatorUpdateIsValid();
Page_BlockSubmit = !Page_IsValid;
return Page_IsValid;
}
function ValidatorCommonOnSubmit() {
var returnValue = !Page_BlockSubmit;
Page_BlockSubmit = false;
return returnValue;
}
function ValidatorOnChange(controlID) {
var cont = document.getElementById(controlID);
var vals = cont.Validators;
var i;
for (i = 0; i < vals.length; i++) {
ValidatorValidate(vals[i]);
}
ValidatorUpdateIsValid();
}
function ValidatorValidate(val) {
val.isvalid = true;
if (typeof(val.evalfunc) == "function") {
val.isvalid = val.evalfunc(val);
}
ValidatorUpdateDisplay(val);
}
function ValidatorOnLoad() {
if (typeof(Page_Validators) == "undefined")
return;
var i, val;
for (i = 0; i < Page_Validators.length; i++) {
val = Page_Validators[i];
var evalFunction = val.getAttribute("evaluationfunction");
if (typeof(evalFunction) == "string") {
eval("val.evalfunc = " + evalFunction + ";");
}
var isValidAttribute = val.getAttribute("isvalid");
if (typeof(isValidAttribute) == "string") {
if (isValidAttribute == "False") {
val.isvalid = false;
Page_IsValid = false;
}
else {
val.isvalid = true;
}
} else {
val.isvalid = true;
}
var controlToValidate = val.getAttribute("controltovalidate");
if (typeof(controlToValidate) == "string") {
ValidatorHookupControl(document.getElementById(controlToValidate), val);
}
}
Page_ValidationActive = true;
}
function RegularExpressionValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.getAttribute("controltovalidate"));
if (value == "")
return true;
var rx = new RegExp(val.getAttribute("validationexpression"));
var matches = rx.exec(value);
return (matches != null && value == matches[0]);
}
function ValidatorTrim(s) {
var m = s.match(/^\s*(.*\S)\s*$/);
return (m == null) ? "" : m[1];
}
function RequiredFieldValidatorEvaluateIsValid(val) {
return (ValidatorTrim(ValidatorGetValue(val.getAttribute("controltovalidate"))) != ValidatorTrim(val.getAttribute("initialvalue")));
}
Vea también
Ejemplos de controles de validación | Ejemplo de control de validación base | Ejemplo de control de validación de campo requerido | Ejemplo de control de validación de expresión regular | Archivo de configuración para ejemplo de control de validación | Página de prueba para ejemplo de control de validación | Desarrollar un control validador