1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <script>
$(function(){
var Verif = (function(){
var Val = [];
return {
set: function(){
this.Val = $.makeArray(arguments); // $.makeArray c'est du jQuery bien entendu !
},
get: function(n){
if (n > this.Val.length - 1){
throw "Erreur dans l'objet Verif, l'index de la valeur requise est supérieur au nombre d'arguments stockés !";
} else {
return this.Val[n];
}
},
integer: function(n){
return /^\d*$/.test(this.get(n));
},
alpha: function(n){
return /^[a-z]*$/i.test(this.get[n]);
},
alphaNum: function(n){
return /^[a-z0-9]*$/i.test(this.get[n]);
},
pair: function(n){
return (this.integer(n) && !(this.get[n] & 1));
},
impair: function(n){
return (this.integer(n) && !this.pair(n));
},
verifie: function(){
var result = [];
for (var n in this.Val){
result.push("this.Val[" + n + "] = " + this.Val[n]);
result.push("integer[" + n + "] = " + this.integer(n));
result.push("alpha[" + n + "] = " + this.alpha(n));
result.push("alphaNum[" + n + "] = " + this.alphaNum(n));
result.push("pair[" + n + "] = " + this.pair(n));
result.push("impair[" + n + "] = " + this.impair(n));
result.push("------------");
}
return result.join("\n");
}
}
})();
try {
Verif.set('coucou', 23, 34, 'null');
alert(Verif.verifie());
}
catch(e){
alert(e);
}
});
</script> |
Partager