Cet article partagera avec vous un cadre de vérification JS très pratique pour implémenter le code source de votre référence. Le contenu spécifique est le suivant
Méthodes et principes clés:
if (! eval (scriptcode)) Dans la fonction vérifie la fonction (thisInput) {return false; }Exemple d'appel:
Copiez le code de code comme suit: <input type = "text" name = "Progress_payment_two" id = "Progress_payment_two" inputName = "Progress Payment 2 Ratio (%)" validate = "isNumeric; notnull" maxLength = "350" value = "" />
La méthode ISNUMERIER et la méthode Notnull seront automatiquement appelées pendant la vérification et les informations de résultat de vérification seront renvoyées.
var configValidateInfotype = "WriteAlert"; // Prise en charge de WriteAlert et WritePage, "WritePage; WriteAlert" var rmTempStatusisSalert = false; var rmTempStatusisfocus = false; var beginValidate = true; var set_all_venus_inputs_default = true; String.prototype.trim = function () {return this.replace (/ (^ / s *) | (/ s * $) / g, ""); } fonction CheckAllForms () {var checkResult = true; rmTempStatusisAlert = 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 = documents.forms [i] .Elements [j]; if (thisInput.type! = "Hidden" && thisInput.type! = "Button" &&! (thisInput.id.indexof ("tf _")> = 0 && thisInput.id.indexof ("_ tf")> 0) && thisInput.clientWidth! = 0 && thisInput.style && thisInput.style.display! = 'None') {/ * if (validatestr! = null && validatestr.Length> 0) {if (thisInput.tagname == 'textarea' && srcstry! = ') {srcstr = reversera (srcStr); if (thisInput.maxLength! = null && thisInput.maxLength> 0) {if (thisInput.tagname == 'textarea' && srcstr! = '') {srcstr = remplaceEnt (srcstr); if (thisInput.maxLength! = null && thisInput.maxLength> 0) {if (getTrLength (srcstr)> thisInput.maxLength) {writeValidateInfo (thisInput, "La longueur d'entrée à la mise au point est trop longue / n s'il vous plaît assurez-vous que la longueur d'entrée est dans" + frmlLength + "); return fall;}}} if (thisInput.id && thisInput.id.indexof ("fournisseur_id_ref _")! = - 1 && document.getElementyid ("UnionDiv") && document.getElementyid ("UnionDiv"). Style.Display == "Aucun") {Continuation; CheckResult = false; Validatestr.Split (';'); validatetemp [i] + "('" + s + "'," + "thisInput)" if (validatetemp [i] .Indexof ("(") <0 || validatetemp [i] .indexof (")") <0) {scriptcode = "javascrip {return false;}} Catch (e) {alert ("Vérifier la fonction" + validatemp [i] + " inslen = document.forms [i] .elements.length; for (var j = 0; j <inslen; j ++) {var frm = document.forms [i] .Elements [j] if (frm.type! = "Hidden" && frm.type! = "Button" &&! (Frm.id.indexof ("tf _") frm.id.indexof ("_ tf")> 0)) {if (frm.valida! = null) {setVENUSInputDefault (frm); _Frm.style.borderColor = ""; str.replace ('/ r', '') //alert(str.indexof('/n ')) if (str.indexof (' / n ')! = - 1 && str.indexof (' / r ')! = - 1) {return remplaceenter (str); _str; str.replace ('(', '// u0028'); str = str.replace ('(', '// u0028'); str = str.replace ('(', '// u005c'); str = str.replace ('//', '// u0027'); str = str.replace ('(', '// u0028'); Str = Str.replace ('(', '// u0028'); Str = Str. str.replace (')', '// u0029'); i = 0; i <_validatestr.Length; i ++) {if (_validatestr [i] == _validator) return true;} return;} function writevalidaInfo (information, thisObj) {var entrée) if (configValidateInfotype.Indexof ("writePage")> = 0) {writeValidaIndFoafterObject (info, thisObj);} if (configValidaIdAnfotype.Indexof ("writeAlert")> = 0) {writeValidAnfoTATAT. setVeUSInputError (thisObj); if (_frm.tagname! = "select") {_frm.select ();} _frm.style.borderstyle = " _Frm.style.backgroundcolor = "Highlight"; WriteValidaIndFoafterObject (info, thisObj) {// Écriture d'informations de vérification var valideinfoobj = null; thisObj.nextsibling.tagname.toupperase () == "font" && thisobj.nextsibling.nextsibling.tagname.toupperase () == "span" && thisobj.nextsibling.nextsibling.classname == "Font_remain_promipt") {valatedinfoobj = thisObj.nextsibling.NextSibling;} else {thisObj.insertAdjacenthtml ("Afterend", "<font> </font> <span class = font_remain_prompt> </span>"); > 0 || info.length> 0) {validerInfoobj.innerhtml = info;}} function if (thisObj.nextsibling! = null && thisObj.nextsibling.type == "Hidden") {thisObj = getValidingPosition (thisObj.nextsibling); == 0) {inputName = thisInput.name; ++; } return len;} /************************************************************ranmin validate******************************************************************************************/function notNull(s, thisInput) { //Cannot be empty//Remove space essayez {thisInput.value = thisInput.value.trim ();} catch (e) {} s = s.trim (); thisInput); return false;} return true;} function isjine (s, thisInput) {// ne peut pas être vide var a = / ^ [0-9] * (/. } else {return true;}} function ismobile (s, thisInput) {// Numéro de mobile: il doit commencer avec un numéro, sauf pour le nombre, il peut contenir OBJ = nouveau Array () obj [0] = "13"; Int ++) {if (s.SubString (0,2) == obj [int]) {Mob = Mob + 1; ]? ([-]? (((/ d) | []) {1,12}) + $ /; if (! Patn.exec (s)) {writeValidateInfo ('Veuillez entrer un numéro mobile légal! thisInput.value = thisInput.value.trim ();} catch (e) {} s = s.trim (); thisInput); return false;} return true;} function iStel (s, thisInput) {// il s'agit d'un numéro de téléphone normal et d'un numéro de fax: il peut démarrer avec "+" true; ISTELFORFAX (S, thisInput) {// Il s'agit d'un numéro de téléphone normal et d'un numéro de fax: il peut commencer par "+", à l'exception du numéro, il peut contenir Patn = / ^ (/ d) {3,4} [-] (/ d) {7,8} $ /; Numéro: il peut commencer avec "+", à l'exception du nombre, il peut contenir if (! Patn.exec (s)) {writeValidAnInfo ('Veuillez entrer un numéro de fax juridique, par exemple: 010-8888888!', thisInput); } S = S.Trim (); thisInput.value = thisInput.value.trim ();} catch (e) {} s = s.trim (); un nombre // supprimez l'espace {thisInput.value = thisInput.value.trim ();} Catch (e) {} S = S.Trim (); (Digits.Indexof (C) == -1) {WriteValidaInfo ("Veuillez entrer le numéro!", ThisInput); if (s.length == 0) Try {if (thisInput.value <= 0) {writeValidaInfo ("La valeur d'entrée doit être supérieure à zéro!", thisInput); S = S.Trim (); / ^ (([0-9a-za-z] +) | ([0-9a-za-z] + [_. 0-9a-za-z -] * [0-9a-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;} else {writeValidaInfo ("s'il vous plaît entrez une fonction de messagerie valide et légale!", thisInput); Valeur! ', ThisInput); / ********************************************************************************************************************** *********************************************************************************************************************** Vérifiez Notnull ******************************************************************** / Fonction NotNullwithouttrim (S, ThisInput) {// Yes "" // Supprimez l'espace. 0) {WriteValidaInfo ('Veuillez entrer, cet élément ne peut pas être vide! == 0) {return true;} var reg = "0123456789"; ISNORMALSTRONWEB (S, ThisInput) {// Il s'agit d'un caractère normal (tag non-html) if (S.SubString (0,1) == "<" || if (! holdcode (s)) {writeValidateInfo ("La pleine largeur ne peut pas être entrée au focus /" ・ / "//" `` / "//" `` / "//" `` / "//" - / "//" `` / "//" `` / "//" '' / ". 0) {if (s.indexof ("/" ")> -1) {writeValidateInfo (" Les citations doubles ne peuvent pas être entrées au focus !! ", thisInput); return false;} if (" s.indexof ("/ '" ")> -1) {writeValidaIndfo (" Single Quotes ne peut pas être entré à la mise au point ", ceInput); return false;} if (S.IndExof (") -1) {writeValidateInfo ("" ne peut pas être entré au focus ", thisInput); return false;}} return true;} // fonction de la liste de fonction de base jtrim (str) {// de la fonction de space var i = 0; var len = str.length; if (str ==" ") return = tr); var j = len -1; var flagBeg && i <len) {if (str.charat (i) == ") {i = i +; ""); if (chiffres.indexof (c) == -1) {return false;} i ++;} return true;} function ischinese (s) {// / *****************************************************************************************************************. perfectionné) ******************************************************************************* / FONCTION Holdcode (str) {pour (var i) validateform (current_form) {for (var i = 0; i <current_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]. == "/>" || Current_Form [i] .value.SubString (0,1) == "") {alerte ("Le focus ne peut pas démarrer avec <ou /> Space"); alert("The input length is too long at the focus/n Please make sure that the input length is within " +current_form[i].maxLength+"); current_form[i].focus(); current_form[i].select(); return false; } if (!HoldCode(current_form[i].value)){ alert("The full-width cannot be entered at the focus / "・ /" // "proue "scriptdefine") {return true;} if (current_form [i] .value.indexof ("/" ")> -1) {alert (" Double Quotes ne peut pas être entré sur Focus "); L'espace try {thisInput.value = thisInput.value.trim ();} Catch (e) {} S = S.Trim (); Scale);} Catch (E) {}} Fonction de vérification (s, maxLength, Scale) {// Vérifiez le kilométrage en cours d'exécution, décimal, entièrement entièrement if (! isfloatNumber (s)) {return false;} if (s.indexof (".")> 0) {if (s.indexof (".") <= maxLength && (math.round (s * (pow (MaxLength - Scale) + "Bits!"); thisInput.value = thisInput.value.trim (); (Digits.Indexof. issecarch (s, thisInput) {// ne peut pas entrer des caractères illégaux si (s.length == 0) return true; Patn = / ^ [^ `~! @ # $% ^ & * () + = | ///] [/] / {/} :; '/,. /_^/{/|/.//,<>"'_ }/ // ====================================================================. ======================================================================. * Vérifiez le nombre (Numéro positif contenant Decimal). /^/d+(/./d+)?$/; thisInput.value = thisInput.value.trim ();} Catch (e) {} value = true;} / ** * Vérifiez le nombre (le chiffre entier maximal est à 10 chiffres et peut être pris avec des décimales) * / Fonction ValidaTenumericandLength (Value, ThisInput) {// Supprimez l'espace Try {thisInput.value = thisInput.value.trim (); } var reg = /^/d; ThisInput) {// Supprimez l'espace {thisInput.value = thisInput.value.trim (); WriteValidaInfo ("Veuillez entrer un nombre (jusqu'à 16 chiffres entiers, maximum 2 places décimales)!", thisInput); Value =.Trim (); true;} / ** * Vérifiez le nombre (5,2) * / fonction isNum5p2 (valeur, thisInput) {// supprimer l'espace {thisInput.value = thisInput.value.trim ();} catch (e) {} Value = Value.trim (); /^(-)?/d; essayez {thisInp ut.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = /^/w+(@-+. if (! reg.test (valeur)) {writeValidateInfo ("Veuillez saisir l'adresse e-mail correcte!", thisInput); retourne false; } return true;} / ** * Vérifiez la carte d'identité (carte d'identité 15 bits ou 18 bits). * / Fonction CheckIdCard (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = / ^ / d {15} (/ d {2} [a-za-z0-9])? $ /; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez saisir le numéro d'identification correct!", thisInput); retourne false; } return true;} / ** * Vérifiez le code postal. * / Fonction CheckPostCode (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = / ^ [0-9] / d {5} $ /; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez saisir le code postal correct!", thisInput); retourne false; } return true;} / ** * Vérifiez s'il s'agit d'un caractère chinois. * / Fonction CheckChinese (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = / ^ [/ u0391- / uffe5] + $ /; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez entrer les caractères chinois!", thisInput); retourne false; } return true;} / ** * Vérifiez s'il s'agit d'un caractère illégal. *! if (! reg.exec (valeur)) {writeValidateInfo ("Le caractère entré contient des caractères spéciaux, veuillez vous remettre!", thisInput); retourne false; } return true; } Fonction CheckMoney (s, inputName) {// Supprimez l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} s = s.trim (); if (s.Length == 0) {return true; } if (s == "") {writeValidateInfo ("Le montant ne peut pas être vide!", inputName); retourne false; } if (isfloatNumber (s, inputName) == false) {writeValidateInfo ("Illégal Montant Value!", InputName); retourne false; } var maxLength = 10; échelle var = 2; return checkNumberImpl (s, maxLength, Scale, inputName);} / ** * Vérifiez si le score est 0-100 * / fonction isadultage (str, thisInput) {// est un entier // supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} str = str.trim (); if (str.length == 0) {return true; } if (parseInt (str) <0 || parseInt (str)> 100) {writeValidateInfo ('Veuillez saisir un score juridique (entre 0-100)!', thisInput); retourne false; } return true;} / ** * Niveau 6 Paramètres d'intensité (numéro, majuscules, lettres minuscules, caractères spéciaux, longueur> = 6, longueur> = 10) * Si le mot de passe est vide, renvoie 0 * / fonction 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) // Nombre sum [0] = 1; else if (c> = 65 && c <= 90) // sum majuscule [1] = 1; else if (c> = 97 && c <= 122) // Sum minuscule [1] = 1; Else // Sum de caractère spécial [2] = 1; } var niveau = sum [0] + sum [1] + sum [2]; if (pwd.length> = 8) niveau ++; Niveau de retour;} fonction isbiggerzero (valeur, thisInput) {// déjà un nombre, alors doit être supérieur à 0 if (thisInput.value <= 0) {writeValidateInfo ('Veuillez entrer un nombre supérieur à zéro!', thisInput); retourne false; } return true;} fonction isNonnegative (value, thisInput) {if (thisInput.value <0) {writeValidAdInfo ('Veuillez entrer un numéro non négatif!', thisInput); retourne false; } return true;} / ** * Vérifier le nombre (20,6) * / fonction isNum20p6 (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = /^(-)?/d{1,14 }(/./d{1,6 })?$/; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez entrer un nombre (le maximum de 14 chiffres entiers et le maximum de 6 chiffres décimaux)!", thisInput); retourne false; } return isBiggerzero (valeur, thisInput);} / ** * Vérifiez le nombre (18,6) * / fonction isNum18p6 (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = /^(-)?/d{1,12 }(/./d{1,6 })?$/; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez entrer un nombre (le maximum de 12 chiffres entiers et le maximum de 6 chiffres décimaux)!", thisInput); retourne false; } return isBiggerZero (valeur, thisInput);} fonction isNonnegative20p6 (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = /^(-)?/d{1,14 }(/./d{1,6 })?$/; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez entrer un nombre (le maximum de 14 chiffres entiers, le maximum de 6 chiffres décimaux)!", thisInput); retourne false; } return isNonnegative (value, thisInput);} / ** * Verify Number (20,4) * / function isNum20p4 (value, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = /^(-)?/d{1,16 }(/./d{1,4 })?$/; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez entrer un nombre (le maximum de 16 chiffres entiers et le maximum de 4 décimales)!", thisInput); retourne false; } return isbiggerzero (valeur, thisInput);} / ** * La quantité d'un seul lot de marge entrée par le fournisseur ne peut être qu'un entier positif et ne peut être exact que pour des centaines de chiffres * / fonction isdpcbzj (valeur, thisInput) {// supprimer l'espace try {thisInput.value = thisInput.value.Trim (); } catch (e) {} value = valeur.trim (); if (value.length == 0) {return true; } var reg = / ^ [1-9] / d * 00 $ /; if (! reg.test (valeur)) {writeValidateInfo ("Veuillez saisir le montant de marge correct!", thisInput); retourne false; } Retour True;} // Jugement que l'année de début de l'année d'appel d'offres ne peut pas être supérieure à la fonction de fin de l'année valideyear (startyear, endyear, flag) {if (startyear> endyear) {if (drape == 1) {alert ("le mois de départ ne peut pas être plus grand que le mois de fin"); retourne false; } else {alert ("L'année de départ de l'appel d'offres ne peut pas être supérieure à l'année de fin"); retourne false; }} retourne true;}Ce qui précède concerne cet article, et j'espère qu'il sera utile pour tout le monde d'apprendre la programmation JavaScript.