Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------- string is null or empty ----------
- String.prototype.isNullOrEmpty = function (varName) {
- if (typeof (this.valueOf()) != 'string') {
- throw new Error(varName + "must be String");
- }
- if (!this.valueOf()) {
- throw new Error(varName + " cannot be undefined or empty");
- }
- }
- // ---------- is integer in range ----------
- Number.prototype.isIntegerAndInRange = function (minValue, maxValue, varName) {
- if (typeof ( this.valueOf() ) != 'number') {
- throw new Error(varName + " must be Number.");
- }
- if (this === parseInt( this.valueOf() , 10)) {
- throw new Error(varName + " must be Integer.");
- }
- if (this.valueOf() < minValue || this.valueOf() > maxValue) {
- throw new Error(varName + " must be Integer in range[" + minValue + "..." + maxValue + "].");
- }
- return true;
- }
- // ---------- is boolean ----------
- Boolean.prototype.isBoolean = function (varName) {
- if (typeof (this.valueOf()) != 'boolean') {
- throw new Error(varName + " must be Boolean value.");
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment