15
rated 0 times
[
16]
[
1]
/ answers: 1 / hits: 53552
/ 14 Years ago, thu, december 2, 2010, 12:00:00
Is there anyway to detect if a JavaScript object is a regex?
For example, I would like to do something like this:
var t = /^foo(bar)?$/i;
alert(typeof t); //I want this to return regexp
Is this possible?
Thanks!
EDIT: Thanks for all the answers. It seems I have two very good choices:
obj.constructor.name === RegExp
or
obj instanceof RegExp
Any major pros/cons to either method?
Thanks again!
More From » regex