1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-19 12:52:11 +01:00

Update: Much smaller numeric type detection method, based on isNumeric in jQuery. Also a whole lot faster.

This commit is contained in:
Allan Jardine 2012-11-02 08:33:07 +00:00
parent a073515b20
commit 33d3667bbe
2 changed files with 10 additions and 90 deletions

View File

@ -11654,53 +11654,13 @@
* Function: - * Function: -
* Purpose: Check to see if a string is numeric * Purpose: Check to see if a string is numeric
* Returns: string:'numeric' or null * Returns: string:'numeric' or null
* Inputs: mixed:sText - string to check * Inputs: mixed:data - string to check
*/ */
function ( sData ) function ( data )
{ {
/* Allow zero length strings as a number */ return data==='' || data==='-' || (!isNaN( parseFloat(data) ) && isFinite( data )) ?
if ( typeof sData === 'number' ) 'numeric' :
{ null;
return 'numeric';
}
else if ( typeof sData !== 'string' )
{
return null;
}
var sValidFirstChars = "0123456789-";
var sValidChars = "0123456789.";
var Char;
var bDecimal = false;
/* Check for a valid first char (no period and allow negatives) */
Char = sData.charAt(0);
if (sValidFirstChars.indexOf(Char) == -1)
{
return null;
}
/* Check all the other characters are valid */
for ( var i=1 ; i<sData.length ; i++ )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
{
return null;
}
/* Only allowed one decimal place... */
if ( Char == "." )
{
if ( bDecimal )
{
return null;
}
bDecimal = true;
}
}
return 'numeric';
}, },
/* /*

View File

@ -5,53 +5,13 @@ $.extend( DataTable.ext.aTypes, [
* Function: - * Function: -
* Purpose: Check to see if a string is numeric * Purpose: Check to see if a string is numeric
* Returns: string:'numeric' or null * Returns: string:'numeric' or null
* Inputs: mixed:sText - string to check * Inputs: mixed:data - string to check
*/ */
function ( sData ) function ( data )
{ {
/* Allow zero length strings as a number */ return data==='' || data==='-' || (!isNaN( parseFloat(data) ) && isFinite( data )) ?
if ( typeof sData === 'number' ) 'numeric' :
{ null;
return 'numeric';
}
else if ( typeof sData !== 'string' )
{
return null;
}
var sValidFirstChars = "0123456789-";
var sValidChars = "0123456789.";
var Char;
var bDecimal = false;
/* Check for a valid first char (no period and allow negatives) */
Char = sData.charAt(0);
if (sValidFirstChars.indexOf(Char) == -1)
{
return null;
}
/* Check all the other characters are valid */
for ( var i=1 ; i<sData.length ; i++ )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
{
return null;
}
/* Only allowed one decimal place... */
if ( Char == "." )
{
if ( bDecimal )
{
return null;
}
bDecimal = true;
}
}
return 'numeric';
}, },
/* /*