validations.js
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
jQuery(function (){
jQuery('#range_submit').live("click", validate_new_range_configuration);
jQuery('#metric_configuration_submit').live("click", validate_metric_configuration);
});
function validate_metric_configuration(){
var code = jQuery('#metric_configuration_code').val();
if (is_null(code))
{
alert("Code must be filled out");
return false;
}
return true;
}
function is_null(value){
if(value == "" || value == null){
return true;
}
return false;
}
function IsNotNumeric(value){
if(value.match(/[0-9]*\.?[0-9]+/))
{
return false;
}
return true;
}
function IsNotHexadecimal(value){
if(value.match(/[0-9a-fA-F]{1,8}/))
{
return false;
}
return true;
}
function validate_new_range_configuration(event){
var label = jQuery("#range_label").val();
var beginning = jQuery("#range_beginning").val();
var end = jQuery("#range_end").val();
var color = jQuery("#range_color").val();
var grade = jQuery("#range_grade").val();
if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade))
{
alert("Please fill all fields marked with (*)");
return false;
}
if (IsNotNumeric(beginning) || IsNotNumeric(end) || IsNotNumeric(grade))
{
alert("Beginning, End and Grade must be numeric values");
return false;
}
if (beginning > end)
{
alert("End must be greater than Beginning");
return false;
}
if (IsNotHexadecimal(color)){
alert("Color must be an hexadecimal value");
return false;
}
return true;
}