var GPEMAILFORMAT = "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; // Suprimer les espaces en fin de chaine String.prototype.rtrim = function() { return this.replace(/\s*$/g, ''); } // Suprimer les espaces en début de chaine String.prototype.ltrim = function() { return this.replace(/^\s*/g, ''); } // Suprimer les espaces en début et fin de chaine String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ''); } // URL-encoder la chaine String.prototype.urlencode = function(){ return encodeURIComponent(this); } // URL-decoder la chaine String.prototype.urldecode = function(){ return decodeURIComponent(this); } // Tester si la chaine est de type numeric String.prototype.isnum = function(){ var re = new RegExp("^\\d+$", "gi") return this.match(re); } String.prototype.isnumlen = function(length){ var re = new RegExp("^[0-9]{" + length + "}$", "gi") return this.match(re); } String.prototype.isStringNumberValue = function() { var re = /^[a-zA-Z0-9]+([\s]?[a-zA-Z0-9])*$/; return this.trim().match(re); } String.prototype.isStringValue = function() { var re = /^[a-zA-Z]+([\s]?[a-zA-Z])*$/; return this.trim().match(re); } String.prototype.isPostalCodeValue = function() { var re = /^0[1-9][0-9]{3}$|^[1-9][0-9]{4}$/; return this.trim().match(re); } String.prototype.isPhoneNumberValue = function() { var re = /^0[1-9][0-9]{8}$/; return this.trim().match(re); } String.prototype.isPhoneHomeValue = function() { var re = /^0[123459][0-9]{8}$/; return this.trim().match(re); } String.prototype.isPhoneMobileValue = function() { var re = /^0[67][0-9]{8}$/; return this.trim().match(re); } // Tester si la chaine est vide String.prototype.isempty = function(){ return (0 == this.trim().length); } // Tester la chaine si elle est de type numeric String.prototype.isemail = function(){ //var re = new RegExp("^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\\w]*[0-9a-zA-Z])*\\.)+[a-zA-Z]{2,9})$", "gi") var re = new RegExp(GPEMAILFORMAT, "gi"); return this.match(re); } // padLeft(Integer) // padLeft(Integer, String) String.prototype.padLeft = function() { if (arguments.length == 0) {return this;} if (arguments.length >= 1 && isNaN(arguments[0])) {return this;} if (arguments[0] < 0) {return this;} var strThis = this; var intLength = parseInt(arguments[0], 10); var strChar = String.fromCharCode(32); if (arguments.length == 2) { strChar = '' + arguments[1]; } while (strThis.length < intLength) { strThis = strChar + strThis; } return strThis; } // padRight(Integer) // padRight(Integer, String) String.prototype.padRight = function() { if (arguments.length == 0) {return this;} if (arguments.length >= 1 && isNaN(arguments[0])) {return this;} if (arguments[0] < 0) {return this;} var strThis = this; var intLength = parseInt(arguments[0], 10); var strChar = String.fromCharCode(32); if (arguments.length == 2) { strChar = '' + arguments[1]; } while (strThis.length < intLength) { strThis = strThis + strChar; } return strThis; }