String.prototype.validate = function(expression) { var boolean; if (expression instanceof RegExp) boolean = expression.test(this); return boolean; }; alert('some-string'.validate(/^.*-s/i));