//usage: var str = " somestring ".trim();
//output: "somestring"
//Credits to http://blog.stevenlevithan.com/archives/faster-trim-javascript
String.prototype.trim = function () {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};
String.isNullOrEmpty = function (value) {
try {
value = value.toString();
} catch (e) {
return true;
}
return (!value || value === undefined || value === "" || value.length === 0);
};
String.isNullOrWhiteSpace = function (value) {
return (String.isNullOrEmpty(value.trim()));
};
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function (from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
var militaryTimeFixer = function (dt) {
var result = dt;
if (new Date(dt) == "Invalid Date") {
result = dt.replace(/am|pm/i, "");
}
return result;
};
//Checks if the start date is before the end date
//returns true if end is later than start
dateCompare = function (start, end) {
var result = false;
var testdt1 = new Date(militaryTimeFixer(start.toString()));
var testdt2 = new Date(militaryTimeFixer(end.toString()));
result = (testdt1 <= testdt2);
return result;
};
function isUnsignedInteger(s) {
return (s.toString().search(/^[0-9]+$/) === 0);
}
function isDate(value) {
var dateRegEx = new RegExp(/^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/);
if (dateRegEx.test(value)) {
return true;
}
return false;
}
function isDateTime(value){
var dateTimeRegEx = new...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.