Skip to content

Commit

Permalink
Added a generic regex method
Browse files Browse the repository at this point in the history
e.g. methods.regex(/[a-zA-Z][a-zA-Z0-9_]/)('someVariable')
  • Loading branch information
jameslnewell committed Apr 30, 2014
1 parent ccb323a commit b11d51f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,23 @@ exports.matches = function(attr) {
*/
exports.numbersOnly = function(val) {
return patterns.numbersOnly.test(val);
};
};

/**
* Check if a value matches the pattern
* @param {String|RegExp} pattern
* @return {Function}
*/
exports.regex = function(pattern) {

if (typeof pattern === 'string') {
pattern = new RegExp(pattern);
}

return function(val) {
if(val){
return type(val) === 'string' && pattern.test(val);
}
};

};

0 comments on commit b11d51f

Please sign in to comment.