source: admin/WebConsole/jscripts/validators.js @ 8626306

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 8626306 was c78cd32, checked in by ramon <ramongomez@…>, 12 years ago

#452 #585: Mejorar la validación de datos en formulario de propiedades de aulas:

  • Comprobar direcciones IP (en general).
  • Comprobar URL (nueva).
  • Comprobar consistencia en datos de validación (solo este formulario).

git-svn-id: https://opengnsys.es/svn/branches/version1.0@3737 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 2.4 KB
Line 
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// Validar expresión regular.
21function validate_expr(value, epx) {
22        var expr = new RegExp(epx);
23        return (value.search(expr) == 0);
24}
25
26// Validar expresión ignorando diferencias entre mayúsculas y minúsculas.
27function validate_expr_nocase(value, epx) {
28        var expr = new RegExp(epx, "i");
29        return (value.search(expr) == 0);
30}
31
32function validate_number(value) {
33        return validate_expr(value, "^\\d*$");
34}
35
36function validate_alphanum(value) {
37        return validate_expr(value, "^\\w*$");
38}
39
40function validate_notnull(value) {
41        return validate_expr(value, "^.+$") && !validate_expr(value, "^\\s*0\\s*$");
42}
43
44function validate_number_notnull(value) {
45        return validate_number(value) && validate_notnull(value);
46}
47
48function validate_alphanum_notnull(value) {
49        return validate_number(value) && validate_notnull(value);
50}
51
52// Validar dirección IPv4.
53function validate_ipadress(value) {
54        var octet = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])';
55        var regex = '^((?:' + octet + '\\.){3}' + octet + ')?$';
56        return validate_expr(value, regex);
57}
58
59function validate_ipadress_notnull(value) {
60        return validate_ipadress(value) && validate_notnull(value);
61}
62
63// Validar URL.
64function validate_url(value) {
65        var octet = '(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])';
66        var regex = '^((ht|f)tps?:\/\/(([a-z0-9]+([\.\-a-z0-9]+)?\.[a-z]{2,5})|((' + octet + '\\.){3}' + octet + '))(:[0-9]{2,5})?(\/.*)?)?$';
67        return validate_expr_nocase(value, regex);
68
69}
70
71function validate_url_notnull(value) {
72        return validate_url(value) && validate_notnull(value);
73}
74
75function validate_nameimagefile(value) {
76        return validate_expr(value, "^[0-9a-zA-Z]*$");
77}
78
79
80function validation_highlight(field) {
81        field.focus();
82        field.style.border = "1px solid red";
83        field.style.background = "#fee";
84}
85
Note: See TracBrowser for help on using the repository browser.