~ubuntu-branches/ubuntu/trusty/libcommons-validator-java/trusty

« back to all changes in this revision

Viewing changes to src/javascript/org/apache/commons/validator/javascript/validateByte.js

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 13:35:53 UTC
  • Revision ID: james.westby@ubuntu.com-20041119133553-qtl7whjkjv9q1rbd
Tags: upstream-1.3
ImportĀ upstreamĀ versionĀ 1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
    /*$RCSfile: validateByte.js,v $ $Revision: 1.9 $ $Date: 2004/03/28 16:53:21 $ */
 
3
    /**
 
4
    * Check to see if fields are a valid byte.
 
5
    * Fields are not checked if they are disabled.
 
6
    * <p>
 
7
    * @param form The form validation is taking place on.
 
8
    */
 
9
    function validateByte(form) {
 
10
        var bValid = true;
 
11
        var focusField = null;
 
12
        var i = 0;
 
13
        var fields = new Array();
 
14
        var formName = form.getAttributeNode("name"); 
 
15
        oByte = eval('new ' + formName.value + '_ByteValidations()');
 
16
 
 
17
        for (x in oByte) {
 
18
            var field = form[oByte[x][0]];
 
19
 
 
20
            if ((field.type == 'hidden' ||
 
21
                field.type == 'text' ||
 
22
                field.type == 'textarea' ||
 
23
                field.type == 'select-one' ||
 
24
                field.type == 'radio')  &&
 
25
                field.disabled == false) {
 
26
 
 
27
                var value = '';
 
28
                // get field's value
 
29
                if (field.type == "select-one") {
 
30
                    var si = field.selectedIndex;
 
31
                    if (si >= 0) {
 
32
                        value = field.options[si].value;
 
33
                    }
 
34
                } else {
 
35
                    value = field.value;
 
36
                }
 
37
 
 
38
                if (value.length > 0) {
 
39
                    if (!isAllDigits(value)) {
 
40
                        bValid = false;
 
41
                        if (i == 0) {
 
42
                            focusField = field;
 
43
                        }
 
44
                        fields[i++] = oByte[x][1];
 
45
 
 
46
                    } else {
 
47
 
 
48
                        var iValue = parseInt(value);
 
49
                        if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
 
50
                            if (i == 0) {
 
51
                                focusField = field;
 
52
                            }
 
53
                            fields[i++] = oByte[x][1];
 
54
                            bValid = false;
 
55
                        }
 
56
                    }
 
57
                }
 
58
 
 
59
            }
 
60
        }
 
61
        if (fields.length > 0) {
 
62
           focusField.focus();
 
63
           alert(fields.join('\n'));
 
64
        }
 
65
        return bValid;
 
66
    }
 
 
b'\\ No newline at end of file'