abolish
Version:
A javascript object validator.
17 lines (16 loc) • 394 B
JavaScript
;
module.exports = {
name: "regex",
error: ":param failed Regex validation.",
validator: (str, regex) => {
const isRegex = regex instanceof RegExp;
if (typeof str !== "string")
return false;
if (isRegex) {
return regex.test(str);
}
else {
return new RegExp(regex).test(str);
}
}
};