Los ejemplos en este artículo comparten con usted el marco de verificación JS, que es muy práctico para su referencia. El contenido específico es el siguiente
1. Métodos y principios clave:
if (! eval (scriptcode)) en el método de verificación de funciones (thisInput) {return false; }2. Ejemplo de llamada:
Copie el código del código de la siguiente manera: <input type = "text" name = "progress_payment_two" id = "progress_payment_two" inputName = "Progress PAGGO 2 Ratio (%)" Validate = "IsNumeric; NotNull" MaxLength = "350" valor = " /" />>
3. El método isnumérico y el método NotNull se llamarán automáticamente durante la verificación y se devolverá la información del resultado de verificación.
4. El código fuente del marco de verificación es el siguiente
var configValidateInfotype = "WriteAlert"; // Apoya a WriteAlert y WritePage, "WritePage; WriteAlert" var rmtempstatusIsalert = false; var rmtempStatusIsfOcus = false; var beginValidate = true; var set_all_venus_inputs_default = true; String.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, ""); } function checkAllforms () {var checkResult = true; rmtempStatusIsAlt = false; rmtempStatusIsfOcus = false; setallvenusinputsdefault (); for (var i = 0; i <document.forms.length; i ++) {for (var j = 0; j <document.forms [i] .elements.length; j ++) {var thisInput = document.forms [i] .elements [j]; if (thisInput.type! = "Hidden" && thisInput.type! = "Botton" &&! (thisInput.id.indexof ("tf _")> = 0 && thisInput.id.indexof ("_ tf")> 0) && thisInput.clientWidth! = 0 && thisInput.style && thisInput.style.display! = 'Ninguno') { /* if (Validatestr! = Null && Validatestr.length> 0) {if (thisInput.tagName == 'TextArea' && srcstr! = '') {srcstr = reemplazar (srcStrStMeMe == 'textArea' && srcstr! = '') {srcstr = reemplazar (srcstr); if (thisInput.maxLength! = NULL && thisInput.maxLength> 0) {if (thisInput.tagName == 'TextAREA' && srcstr! = '') {srcstr = reemplazante (srcstr); if (thisInput.maxLength! = null && thisInput.maxLength> 0) {if (getStrLength (srcstr)> thisInput.maxLength) {writeValidateInfo (thisInput, "la longitud de entrada en el foco es demasiado larga/n por favor la longitud de entrada está dentro de" +frMaxLength +"); return false;}}}} if (thisInput.id && thisInput.id.indexof ("Suprement_id_ref _")! =-1 && Document.getElementById ("UnionDiv") && Document.getElementById ("UnionDiv"). style.display == "Ninguno") {continúa; {checkResult = false; validatestr.split (';'); "('" + S + "," + "thisInput)" if (validateTemp [i] .indexof ("(") <0 || validateTemp [i] .indexof (")") <0) {scriptCode = "javaScript:" + validateMp [i] + "(s, thisInput)"} if (! {alerta ("verificar la función"+validateTemp [i]+"Hay una excepción, por favor verifique!"+"/n"+e.message); document.forms [i] .elements.length; ) {if (frmm.Validate! = NULL) {setVenUsInputDefault (frm); _FRM.Value! = NULL) {_FRM.Style.BackgroundColor = ""; //alert(Str.indexof('/n ')) if (str.indexof ('/n ')! =-1 && str.indexof ('/r ')! =-1) {return reemplazar (str); str.replace ('//', '// u005c'); str.replace ('(' (',' // u0028 '); str = str.replace (' (',' // u0028 '); str = str.replace (' (',' // u005c '); str = str.replace (' // ',' // u0027 '); str = str.rePlace (' ('(', '// u0028'); str.replace (')', '// u0029'); i = 0; i <_validatestr.length; i ++) {if (_validatestr [i] == _validator) return true; if (configValidateInfotype.indexof ("writePage")> = 0) {WriteValides setVENUSInputError (thisObj); if (_frm.tagname! = "select") {_frm.select (); "Destacado"; thisObj) {// Escribir información de verificación var validateInfoObj = null; thisObj.nextsibling.tagname.ToUpperperCase () == "font" && thisObj.nextsibling.nextsibling.tagname.toupperCase () == "span" && thisObj.nextsibling.nextsibling.classsname == "font_remain_prompt") {valextfoobj = thisObj.NextSibling.NextSibling; 0 || info.length> 0) {validateInfoObj.innerhtml = info; if (thisObj.nextSibling! = null && thisObj.nextSibling.Type == "Hidden") {thisObj = getValidgePosition (thisObj.NextSibling); inputName.length == 0) {inputName = thisInput.name; += 2; Be vacío // El espacio intenta {thisInput.Value = thisInput.Value.trim (); vacío o espacio! ", thisInput); return false;} return true;} function isjine (s, thisInput) {// no puede estar vacío var a =/^[0-9]*(/. [0-9] {1,2})? $/; if (! A.test (s)) {writeValidateinfo (" Hay caracteres ilegales o el número de lugares decimales ex ocessssss (s)) {writeValidateinfo ("Hay caracteres ilegales o el número de lugares de decimales ex ocresssses (s)) {writeValidateinfo (" Hay caracteres ilegales o el número de lugares exseders ex oces). FALSO; obj = nueva matriz () obj [0] = "13"; int ++) {if (s.substring (0,2) == obj [int]) {mob = mob+1; ]? ([[-]? ((((/d) | []) {1,12})+$/; if (! Patrn.exec (s)) {WriteValidateInfo ('¡Ingrese un número de móvil legal!', thisInput); return False;} return true;} ISpost ISpostalcode (s, thisinput) {// es el código postal // eliminar el espacio de espacio; thisInput.Value = thisInput.Value.trim (); thisInput); Verdadero; istelforfax (s, thisInput) {// es un número de teléfono normal y un número de fax: puede comenzar con "+", excepto el número, puede contener "-" // Eliminar el espacio intento {thisInput.value = thisInput.Value.trim () Patrn =/^(/d) {3,4} [-] (/d) {7,8} $/; Número: puede comenzar con "+", excepto el número, puede contener "-" // El space intenta {thisInput.Value = thisInput.Value.trim (); if (! Patrn.exec (s)) {writeValidateInfo ('Por favor ingrese un número de fax legal, por ejemplo: 010-88888888!', thisInput); } s = s.trim (); thisInput.Value = thisInput.Value.trim (); Un número//eliminar el espacio {thisInput.Value = thisInput.Value.trim (); (digits.indexof (c) == -1) {writeValidesiNfo ("¡Ingrese el número!", ThisInput); if (s.length == 0) {return true; Pruebe {if (thisInput.Value <= 0) {writeValidesiNfo ("El valor de entrada debe ser mayor que cero!", thisInput); s = s.trim (); /^(([0-9-Za-Z]+) | ([0-9-Za-Z]+[_. 0-9A-ZA-Z-]*[0-9-ZA-Z]+))@([A-ZA-Z0-9-]+[ .])+([a-Za-Z] {2} | net | net | com | com | gov | gov | mil | mil | org | org | edu | edu | int | int) $/; if (regu.exec (s)) {return true; valor! ', thisInput); /*************************************************************************************************************************************************************************** ********************************************************************************************************************** Verifique NotNull ******************************************************************************************************************************************-- 0) {WriteValidateInfo ('Por favor, este elemento no puede estar vacío!', ThisInput); == 0) {return true; isNormalStronweb (s, thisInput) {// es un carácter normal (etiqueta no html) if (s.substring (0,1) == "<" || s.substring (0,1) == "//" || s.substring (0,1) == "") if (! holdCode (s)) {writeValidateInfo ("El ancho completo no se puede ingresar en el foco/" ・/"//" −/"//" "/" // ""/"//" "/" // ""/"//" "" // ""/// "Característica, este de regreso); regreso;} () (). 0) {if (s.indexof ("/" ")> -1) {writeValidateInfo (" Las cotizaciones dobles no se pueden ingresar en el foco !! ", thisInput); return false;} if (s.indexof ("/"")> -1) {writeValidateInfo ("Las cotizas de una sola no se pueden ingresar en el foco", thisInput); devuelve false;} si ((s.index ("/"/") -1) {writeValidateInfo ("" no se puede ingresar en el enfoque ", thisInput); return false;}} return true;} // función de lista básica jtrim (str) {// function de space var i = 0; var len = str.length; if (str ==" ") return (str); var j = len -1; var flagbegin = Varen = true; verdadero = verdadero) True && i <len) {if (str.charat (i) == "") {i = i+1; ("") if (digits.indexof (c) == -1) {return false; /******************************************************************************************************************* perfected)*********************************************************************/function HoldCode(str){ for(var i=0;i<str.length;i++){ if (str.charCodeAt(i) == 8212 || str.charCodeAt(i) == 183){ return false; } } return true;} function ValidateForm (current_form) {for (var i = 0; i <curtent_form.length; i ++) {if (current_form [i] .type == "text" || current_form [i] .type == "radio") {if (current_form [i] .value.substring (0,1) == "<" || Current_Form [i] .Value.value.value. == "/>" || alerta ("La longitud de entrada es demasiado larga en el enfoque/n, asegúrese de que la longitud de entrada esté dentro de" +current_form [i] .maxLength +"); current_form [i] .focus (); current_form [i] .select (); return;} if (! HoldCode (Current_Form [i] .Value)) {alerta (" alerta no se puede ingresar en el entorno completo en el ingreso en el At the At the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the Width. foco/"・/" // ""/"//" "/" // ""/"//" "/" "/" // "")); current_form [i] .focus (); current_form [i]. "scriptDefine") {return true;} if (current_form [i] .value.indexof ("/" ")> -1) {alerta no se puede ingresar en las cotizaciones dobles en focus"); current_form [i] .focus (); actual_form [i] .select (); space intento {thisInput.Value = thisInput.Value.trim (); escala); if (! isfloatnumber (s)) {return false; (maxlength - escala) + "bits!"); thisInput.Value = thisInput.Value.trim (); (digits.indexof (c) == -1) {WriteValides issearch (s, thisInput) {// no puede ingresar caracteres ilegales si (s.length == 0) return true; Patrn =/^[^`~!@#$%^&*()+= | ///] [/]/{/}:; '/,. <>/?] {1} [^` ~!@$%^& ()+= | ///]/{/}:;',. <>?] {0,5000} $/;; /ALIGO^/{/|/.//,<>"'_h}/font>/; if (! Patrn.exec (s) || // ============================================================== ==========================================================/** * Verifique el número (entero o número positivo que contiene decimal). /^/d+(/./d+)?$/; thisInput.Value = thisInput.Value.trim (); verdadero;}/** * Verificar el número (el dígito entero máximo es de 10 dígitos, y puede tomarse con decimals) */function ValidAtenumeryLength (valor, thisInput) {// elimina el space try {thisInput.value = thisInput.Value.trim (); } var reg =^/d =1,10}(/./d+)?$/; thisInput) {// eliminar el espacio {thisInput.Value = thisInput.Value.trim (); WriteValidesiNfo ("Ingrese un número (hasta 16 dígitos enteros, máximo de 2 decimales)", thisInput); value = value.trim (); verdadero;} /** * Verificar el número (5,2) * /Funcion ISNUM5P2 (Valor, thisInput) {// Eliminar el espacio {thisInput.Value = thisInput.Value.trim (); /^(-)?/D (1,3}(/./d /1,2})?$/; Prueba {thisInp ut.value = thisInput.Value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg = /^/w+(bar-+.font>/w+)*@/w+(bar-font>/w+)*/./w+(ículo-font>/w+)*$/; if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese la dirección de correo electrónico correcta!", ThisInput); devolver falso; } return true;} /*** Verifique la tarjeta de identificación (tarjeta de identificación de 15 bits o 18 bits). */function checkIdCard (valor, thisInput) {// Eliminar el space try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg =/^/d {15} (/d {2} [A-ZA-Z0-9])? $/; if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese el número de identificación correcto!", ThisInput); devolver falso; } return true;} /*** Verifique el código postal. */function checkPostcode (valor, thisInput) {// elimina el space inty {thisInput.value = thisInput.value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg =/^[0-9]/d {5} $/; if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese el código postal correcto!", ThisInput); devolver falso; } return true;} /*** Verifique si es un personaje chino. */function checkChinesSe (valor, thisInput) {// elimina el space inty {thisInput.value = thisInput.value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg =/^[/u0391-/uffe5]+$/; if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese los caracteres chinos!", ThisInput); devolver falso; } return true;} /*** Verifique si es un carácter ilegal. */function checkInValIdString (valor, thisInput) {var reg = /^[^`~!@#$%^&*()+=|//font>&fontience if (! reg.exec (valor)) {writeValidateInfo ("El carácter ingresado contiene caracteres especiales, ¡vuelva a ingresar!", ThisInput); devolver falso; } return verdadero; } function checkMoney (s, inputName) {// Eliminar el space try {thisInput.value = thisInput.value.trim (); } catch (e) {} s = s.trim (); if (s.length == 0) {return true; } if (s == "") {writeValidateInfo ("¡La cantidad no puede estar vacía!", InputName); devolver falso; } if (isfloatNumber (s, inputName) == false) {writeValidateInfo ("Valor de cantidad ilegal!", InputName); devolver falso; } var maxLength = 10; escala var = 2; return checkNumberImpl (s, maxLength, scale, inputName);}/** * Verifique si la puntuación es 0-100 */function isadultage (str, thisInput) {// es un entero // eliminar la prueba de espacio {thisInput.value = thisInput.value.trim (); } catch (e) {} str = str.trim (); if (str.length == 0) {return true; } if (parseInt (str) <0 || parseInt (str)> 100) {writeValidateInfo ('Ingrese una puntuación legal (entre 0-100)!', ThisInput); devolver falso; } return true;} /** * Configuración de intensidad de nivel 6 (número, mayúscula, letras minúsculas, caracteres especiales, longitud> = 6, longitud> = 10) * Si la contraseña está vacía, return 0 * /function pwdStrength (pwd) {var sum = [0, 0, 0]; for (var i = 0; i <pwd.length; i ++) {var c = pwd.charcodeat (i); if (c> = 48 && c <= 57) // numero suma [0] = 1; else if (c> = 65 && c <= 90) // suma upcase [1] = 1; else if (c> = 97 && c <= 122) // suma minúscula [1] = 1; else // suma de caracteres especial [2] = 1; } Var nivel = suma [0] + suma [1] + suma [2]; if (pwd.length> = 8) nivel ++; Nivel de retorno;} function isbiggerZero (valor, thisInput) {// Ya un número, entonces debe ser mayor que 0 if (thisInput.Value <= 0) {writeValidateInfo ('¡Ingrese un número mayor que cero!', thisInput); devolver falso; } return true;} function isNonNegative (valor, thisInput) {if (thisInput.Value <0) {writeValidateInfo ('¡Ingrese un número no negativo!', thisInput); devolver falso; } return true;} /** * Número de verificación (20,6) * /function isNum20p6 (valor, thisInput) {// eliminar space inty {thisInput.value = thisInput.value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg = /^(-)? if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese un número (el máximo de 14 dígitos enteros y el máximo de 6 dígitos decimales)!", thisInput); devolver falso; } return isbiggerZero (valor, thisInput);} /** * Verifique el número (18,6) * /function isNum18p6 (valor, thisInput) {// Eliminar el space inty {thisInput.value = thisInput.value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg = /^(-)? if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese un número (el máximo de 12 dígitos enteros y el máximo de 6 dígitos decimales)!", ThisInput); devolver falso; } return isbiggerZero (valor, thisInput);} función isnonnegative20p6 (valor, thisInput) {// Eliminar el space inty {thisInput.value = thisInput.value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg = /^(-)? if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese un número (el máximo de 14 dígitos enteros y el máximo de 6 dígitos decimales)!", thisInput); devolver falso; } return isNonNegative (valor, thisInput);} /** * Número de verificación (20,4) * /function isNum20p4 (valor, thisInput) {// eliminar space try {thisInput.value = thisInput.Value.trim (); } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg = /^(-)? if (! reg.test (valor)) {writeValidateInfo ("Ingrese un número (el máximo de 16 dígitos enteros y el máximo de 4 decimales)!", ThisInput); devolver falso; } return isbiggerZero (valor, thisInput);} /*** La cantidad de un solo lote de margen ingresado por el proveedor solo puede ser un entero positivo y solo puede ser precisa para cientos de dígitos* /function isDpcbzj (valor, thisInput) {// eliminar el espacio de space intent.ryinput.value = thisinput.value.trim ();; } catch (e) {} value = value.trim (); if (value.length == 0) {return true; } var reg =/^[1-9]/d*00 $/; if (! reg.test (valor)) {writeValidateInfo ("¡Ingrese la cantidad de margen correcta!", ThisInput); devolver falso; } return true;} // juzgar que el año de inicio del año de tierno no puede ser mayor que la función del año final validateyear (startyear, endyear, flag) {if (startyear> endyear) {if (flag == 1) {alerta ("el mes inicial no puede ser mayor que el mes final"); devolver falso; } else {alerta ("El año de inicio de la licitación no puede ser mayor que el año final"); devolver falso; }} return true;}Lo anterior se trata de este artículo, espero que sea útil para el aprendizaje de todos.