Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q816 How can I validate a form field so that it is a fixed size (say 6) and only contains alpha numeric characters?

You are here: irt.org | FAQ | JavaScript | Form | 5 | Q816 [ previous next ]

Try:

<SCRIPT LANGUAGE="JavaScript"><!--
function validate(string,length) {
    if (string.length > length) {
        alert('too long');
        return false;
    }
    if (string.length < length) {
        alert('too short');
        return false;
    }

    var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

    for (var i=0; i<length; i++) {
        if (valid.indexOf(string.charAt(i)) < 0) {
            alert('invalid characters');
            return false;
        }
    }

    return true;
}
//--></SCRIPT>

Feedback on 'Q816 How can I validate a form field so that it is a fixed size (say 6) and only contains alpha numeric characters?'

©2018 Martin Webb