|
Q816 How can I validate a form field so that it is a fixed size (say 6) and only contains alpha numeric characters?
irt.org | Knowledge Base | JavaScript | Form 5 | Q816 [ previous next ]
Q816 How can I validate a form field so that it is a fixed size (say 6) and only contains alpha numeric characters?
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?'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.