1 | /* |
---|
2 | * Copyright (C) 2011 Daniel Garcia <danigm@wadobo.com> |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | function validate_expr(value, epx) { |
---|
21 | var expr = new RegExp(epx); |
---|
22 | return (value.search(expr) == 0); |
---|
23 | } |
---|
24 | |
---|
25 | function validate_number(value) { |
---|
26 | return validate_expr(value, "^\\d*$"); |
---|
27 | } |
---|
28 | |
---|
29 | function validate_alphanum(value) { |
---|
30 | return validate_expr(value, "^\\w*$"); |
---|
31 | } |
---|
32 | |
---|
33 | function validate_notnull(value) { |
---|
34 | return validate_expr(value, "^.+$") && !validate_expr(value, "^\\s*0\\s*$"); |
---|
35 | } |
---|
36 | |
---|
37 | function validate_number_notnull(value) { |
---|
38 | return validate_number(value) && validate_notnull(value); |
---|
39 | } |
---|
40 | |
---|
41 | function validate_alphanum_notnull(value) { |
---|
42 | return validate_number(value) && validate_notnull(value); |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | function validate_ipadress(value) { |
---|
47 | return validate_expr(value, "^\\d+\\.\\d+\.\\d+\\.\\d+$"); |
---|
48 | } |
---|
49 | |
---|
50 | function validate_ipadress_notnull(value) { |
---|
51 | return validate_ipadress(value) && validate_notnull(value); |
---|
52 | } |
---|
53 | |
---|
54 | function validate_nameimagefile(value) { |
---|
55 | return validate_expr(value, "^[0-9a-zA-Z]*$"); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | function validation_highlight(field) { |
---|
60 | field.focus(); |
---|
61 | field.style.border = "1px solid red"; |
---|
62 | field.style.background = "#fee"; |
---|
63 | } |
---|