jQuery.isNumeric (v2)

Revision 2 of this benchmark created by Dominic on


Description

'&&' is lazy, checking !isNaN before running a regex could be quicker.

Preparation HTML

<script src="//code.jquery.com/jquery-1.7.js"></script>

Setup

rdigit = /\d/;
    
    jQuery.isNumeric2 = function( obj ) {
        return obj !== null && !isNaN( obj ) && rdigit.test( obj );
    };

Test runner

Ready to run.

Testing in
TestOps/sec
before
jQuery.isNumeric(NaN);
ready
after
jQuery.isNumeric2(NaN);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.