~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/validateMaxLength.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: validateMaxLength.js,v $ $Revision: 1.10 $ $Date: 2004/03/28 16:53:21 $ */
 
3
    /**
 
4
    * A field is considered valid if less than the specified maximum.
 
5
    * Fields are not checked if they are disabled.
 
6
    * <p>
 
7
    * <strong>Caution:</strong> Using <code>validateMaxLength</code> on a password field in a 
 
8
    *  login page gives unnecessary information away to hackers. While it only slightly
 
9
    *  weakens security, we suggest using it only when modifying a password.</p>
 
10
    * @param form The form validation is taking place on.
 
11
    */
 
12
    function validateMaxLength(form) {
 
13
        var isValid = true;
 
14
        var focusField = null;
 
15
        var i = 0;
 
16
        var fields = new Array();
 
17
        var formName = form.getAttributeNode("name"); 
 
18
 
 
19
        oMaxLength = eval('new ' + formName.value + '_maxlength()');        
 
20
        for (x in oMaxLength) {
 
21
            var field = form[oMaxLength[x][0]];
 
22
 
 
23
            if ((field.type == 'hidden' ||
 
24
                field.type == 'text' ||
 
25
                field.type == 'password' ||
 
26
                field.type == 'textarea') &&
 
27
                field.disabled == false) {
 
28
 
 
29
                var iMax = parseInt(oMaxLength[x][2]("maxlength"));
 
30
                if (field.value.length > iMax) {
 
31
                    if (i == 0) {
 
32
                        focusField = field;
 
33
                    }
 
34
                    fields[i++] = oMaxLength[x][1];
 
35
                    isValid = false;
 
36
                }
 
37
            }
 
38
        }
 
39
        if (fields.length > 0) {
 
40
           focusField.focus();
 
41
           alert(fields.join('\n'));
 
42
        }
 
43
        return isValid;
 
44
    }
 
 
b'\\ No newline at end of file'