1
|
|
2
|
|
3
|
$.extend( DataTable.ext.aTypes, [
|
4
|
/*
|
5
|
* Function: -
|
6
|
* Purpose: Check to see if a string is numeric
|
7
|
* Returns: string:'numeric' or null
|
8
|
* Inputs: mixed:sText - string to check
|
9
|
*/
|
10
|
function ( sData )
|
11
|
{
|
12
|
/* Allow zero length strings as a number */
|
13
|
if ( typeof sData === 'number' )
|
14
|
{
|
15
|
return 'numeric';
|
16
|
}
|
17
|
else if ( typeof sData !== 'string' )
|
18
|
{
|
19
|
return null;
|
20
|
}
|
21
|
|
22
|
var sValidFirstChars = "0123456789-";
|
23
|
var sValidChars = "0123456789.";
|
24
|
var Char;
|
25
|
var bDecimal = false;
|
26
|
|
27
|
/* Check for a valid first char (no period and allow negatives) */
|
28
|
Char = sData.charAt(0);
|
29
|
if (sValidFirstChars.indexOf(Char) == -1)
|
30
|
{
|
31
|
return null;
|
32
|
}
|
33
|
|
34
|
/* Check all the other characters are valid */
|
35
|
for ( var i=1 ; i<sData.length ; i++ )
|
36
|
{
|
37
|
Char = sData.charAt(i);
|
38
|
if (sValidChars.indexOf(Char) == -1)
|
39
|
{
|
40
|
return null;
|
41
|
}
|
42
|
|
43
|
/* Only allowed one decimal place... */
|
44
|
if ( Char == "." )
|
45
|
{
|
46
|
if ( bDecimal )
|
47
|
{
|
48
|
return null;
|
49
|
}
|
50
|
bDecimal = true;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
return 'numeric';
|
55
|
},
|
56
|
|
57
|
/*
|
58
|
* Function: -
|
59
|
* Purpose: Check to see if a string is actually a formatted date
|
60
|
* Returns: string:'date' or null
|
61
|
* Inputs: string:sText - string to check
|
62
|
*/
|
63
|
function ( sData )
|
64
|
{
|
65
|
var iParse = Date.parse(sData);
|
66
|
if ( (iParse !== null && !isNaN(iParse)) || (typeof sData === 'string' && sData.length === 0) )
|
67
|
{
|
68
|
return 'date';
|
69
|
}
|
70
|
return null;
|
71
|
},
|
72
|
|
73
|
/*
|
74
|
* Function: -
|
75
|
* Purpose: Check to see if a string should be treated as an HTML string
|
76
|
* Returns: string:'html' or null
|
77
|
* Inputs: string:sText - string to check
|
78
|
*/
|
79
|
function ( sData )
|
80
|
{
|
81
|
if ( typeof sData === 'string' && sData.indexOf('<') != -1 && sData.indexOf('>') != -1 )
|
82
|
{
|
83
|
return 'html';
|
84
|
}
|
85
|
return null;
|
86
|
}
|
87
|
] );
|
88
|
|