Skip to content

Commit aff579d

Browse files
author
Kurtis LoVerde
committed
cross-browser method of determining object type
1 parent 81bb585 commit aff579d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

jquery.restrictedtextfield.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,20 @@
180180
return value == undefined || value == null || value.length < 1;
181181
}
182182

183+
function isClassName( obj, className ) {
184+
var name = Object.prototype.toString.call( obj ).slice( 8, -1 );
185+
return obj !== undefined && obj !== null && name === className;
186+
}
187+
183188
function _addType( destination, id, fullRegex, partialRegex ) {
184189
if( id == undefined || id == null ) throw "id is undefined";
185190
if( !typeof(id) === "string" ) throw "id should be a string";
186191
if( id.length < 1 ) throw "id is empty";
187192

188193
if( fullRegex == undefined || fullRegex == null ) throw "fullRegex is undefined";
189-
if( fullRegex != undefined && fullRegex != null && typeof(fullRegex) !== "object" || fullRegex.constructor.name !== "RegExp" ) throw "fullRegex should be a regular expression object";
194+
if( !isClassName(fullRegex, "RegExp") ) throw "fullRegex must be a RegExp object";
190195

191-
if( partialRegex != undefined && partialRegex != null && (typeof(partialRegex) !== "object" || partialRegex.constructor.name !== "RegExp") ) throw "partialRegex should be a regular expression object";
196+
if( partialRegex != undefined && partialRegex != null && !isClassName(partialRegex, "RegExp") ) throw "partialRegex must be a RegExp object";
192197

193198
destination[ id ] = { "fullRegex" : fullRegex,
194199
"partialRegex" : partialRegex };

jquery.restrictedtextfield.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)