source: tapas/web/resources/js/tools/controls.js @ 529

Last change on this file since 529 was 529, checked in by rboipsl, 12 years ago

V2 orange

File size: 2.6 KB
Line 
1/**
2 * Created by IntelliJ IDEA.
3 * User: rboipsl
4 * Date: 18/04/12                                     *
5 * Time: 11:26
6 */
7
8function isEmpty( string )
9{
10    return (string.trim() == '');
11}
12
13
14function isMail( email )
15{
16    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( email ));
17}
18
19
20function isInt( number, champ, texte )
21{
22    if( !(/^[0-9]+$/.test( number )) )
23    {
24        alert( champ + ' : ' + texte );
25        return false;
26    }
27    else
28    {
29        return true;
30    }
31}
32
33
34function isFloat( number )
35{
36    //if (!(/^[0-9]+(\.[0-9]+)?$/.test(number))) {
37    return (/^([\+-])?([0-9])*(\.?[0-9]*)?$/.test( number ));
38}
39
40
41function isIP( ip )
42{
43    return (/^(([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+))$/.test( ip ));
44}
45
46
47
48
49function isHourDeg( val )
50{
51    //return (/^(([0-2]*[0-9][0-9])\.([0-2]*[0-9][0-9])\.([0-2]*[0-9][0-9])\.([0-2]*[0-9][0-9]))$/.test(val));
52    if( !(/^([0-2]?[0-9]):([0-5]+[0-9]+):([0-5]+[0-9]+)*$/.test( val )) || isEmpty( val.toString() ) )
53        return false;
54    else
55    {
56        var tab = val.split( ":" )
57
58        if( tab[0] > 24 )
59            return false
60        else
61            return true;
62    }
63
64    //return (/^(([0-9]*[0-9]+):([0-9]+[0-9]+):([0-9]+[0-9]+))$/.test(val));
65}
66
67
68function isDeg( val )
69{
70    //return (/^(([0-2]*[0-9][0-9])\.([0-2]*[0-9][0-9])\.([0-2]*[0-9][0-9])\.([0-2]*[0-9][0-9]))$/.test(val));
71    if( !(/^(([\+-])?[0-9]?[0-9]):([0-9]+[0-9]+):([0-9]+[0-9]+)(\.)?([0-9]*[0-9]*[0-9]*)*$/.test( val )) || isEmpty( val.toString() ) )
72        return false;
73    else
74    {
75        var tab = val.split( ":" )
76
77        if( 90 < tab[0] )
78            return false
79        else
80            return true;
81    }
82
83    //return (/^(([0-9]*[0-9]+):([0-9]+[0-9]+):([0-9]+[0-9]+))$/.test(val));
84}
85
86function isURL( string )
87{
88    return (/^(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/.test( string.toLowerCase() ));
89}
90
91function isValidNum( number )
92{
93    return ( !isEmpty( number ) && isFloat( number ) );
94}
95
96function isSup( number, limit )
97{
98    return ( number >= limit );
99}
100
101function isDiff( val, badvalue )
102{
103    return ( val != badvalue );
104}
105
106function isBetween( number, limitinf, limitsup)
107{
108    return ( number >= limitinf && number <= limitsup );
109}
110
111
112function isValidRange( val1, val2, unit )
113{
114
115    if( 'NM_VACUUM' == unit || 'NM_STANDARD' == unit )
116    {
117        if( isFloat( val1 ) && isFloat( val2 ) && 350 <= parseFloat( val1 ) && 2500 >= parseFloat( val2 ) && parseFloat( val1 ) <= parseFloat( val2 ) ) return true;
118        else return false;
119    }
120    else return 'Unit unknown';
121
122}
Note: See TracBrowser for help on using the repository browser.