// Forms validation Javascript
//
// Version validation.jslib,v 1.11 2000/12/07 00:27:35 kobe Exp
//
// Works for: int, number, word, email, url, text (kind of), imageFile
// Check for missing fields that are required...
// Function setFormProps needs to be added by item.cgi
function validateField(field) {
setFormProps(field.form); // Very inefficient to stick this here, but I see no other way to
// ensure that it gets run before it is needed...
if(field.checkFunction) {
if(!field.checkFunction(field.value)) {
alert("Sorry, this field does not contain a valid "+field.data_type+".");
field.select();
field.focus();
return(false);
}
}
}
var nomatch = 0;
function lockedField() {
alert("Sorry, this field is locked.\nAny changes you make to it will not be saved.");
}
function validateForm(form) {
setFormProps(form);
blanks="";
for (j=0;j
= 5 ) && ( browser.indexOf("Nets") == 0)) {separator = ":"; }
else { separator = "/";}
} else { separator = "/";}
var seppos = val.lastIndexOf(separator);
seppos++;
for(pos = seppos; pos < val.length; pos++)
{
ch = val.charAt(pos);
if(! (((ch >= 'A') && (ch <= 'Z')) ||
((ch >= 'a') && (ch <= 'z')) ||
((ch >= '0') && (ch <= '9')) ||
((ch == '_') || (ch == '.') ||
(ch == '-'))) ) { return(false); }
}
lcval=val.toLowerCase();
if(lcval.length<=4) { return (false) }
if(lcval.lastIndexOf(".zip") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".pdf") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".csv") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".txt") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".htm") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".doc") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".rtf") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".wav") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".mov") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".mpg") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".mp3") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".mer") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".xls") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".exe") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".html") == lcval.length-5) { return(true) }
if(lcval.lastIndexOf(".zip") == lcval.length-5) { return(true) }
return(false);
}
function isWord(val)
{
var pos, ch;
if(val == null)
return(false);
for(pos = 0; pos < val.length; pos++)
{
ch = val.charAt(pos);
if(! (((ch >= 'A') && (ch <= 'Z')) ||
((ch >= 'a') && (ch <= 'z')) ||
((ch >= '0') && (ch <= '9')) ||
((ch == '_') || (ch == '-'))) )
{
return(false);
}
}
return(true);
}
function isPassword(val)
{
var pos, ch;
if(val == null)
return(false);
for(pos = 0; pos < val.length; pos++)
{
ch = val.charAt(pos);
if(! (((ch >= 'A') && (ch <= 'Z')) ||
((ch >= 'a') && (ch <= 'z')) ||
((ch >= '0') && (ch <= '9')) ||
((ch == '_') || (ch == '-'))) )
{
return(false);
}
}
return(true);
}
function isText(val) { // Returns true always
return(true);
}
// This one is also still pretty crude
function isURL(val) { // Returns true if val vaguely resembles a URL, false otherwise
if (val.indexOf(".") == -1) return(false);
else return(true);
}
function isInteger(val) { // Returns true if val is an integer, false otherwise
val=strip(val); // Remove leading and trailing spaces that confuse the issue
len = val.length;
isInt = true;
// This next bit lacks finesse, but is more strict than the implementation that relies
// on a resolvable integer... Probably closer to what we would want in practice
// KNOWN BUG: Does not handle negative numbers properly...
if (len==0) isInt=false; // Field is empty
else {
for (i=0; i= 5 ) && ( browser.indexOf("Nets") == 0)) {separator = ":"; }
else { separator = "/";}
} else { separator = "/";}
var seppos = val.lastIndexOf(separator);
seppos++;
for(pos = seppos; pos < val.length; pos++)
{
ch = val.charAt(pos);
if(! (((ch >= 'A') && (ch <= 'Z')) ||
((ch >= 'a') && (ch <= 'z')) ||
((ch >= '0') && (ch <= '9')) ||
((ch == '_') || (ch == '.') ||
(ch == '-'))) )
{
return(false);
}
}
lcval=val.toLowerCase();
if(lcval.length<=4) { return (false) }
if(lcval.lastIndexOf(".gif") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".jpg") == lcval.length-4) { return(true) }
if(lcval.lastIndexOf(".png") == lcval.length-4) { return(true) }
if(lcval.length<=5) { return (false) }
if(lcval.lastIndexOf(".jpeg") == lcval.length-5) { return(true) }
return(false);
}
function checkPassword(field1,field2) {
usingpasswords = 1;
nomatch = 0;
if (field1 == field2) {
return(true);
} else {
nomatch = 1;
return(false);
}
}
function editList(resource, listname, script)
{
window.open(script+ '?ACTION=editlist&RESOURCE=' + resource + '&listname=' + listname,
'EditList',
'toolbar=no,location=no,directories=no,menubar=no,' +
'scrollbars=yes,resizable=yes,width=640,height=400');
}
function openWin(url, width, height)
{
window.open(url,
'ViewFile',
'toolbar=no,location=no,directories=no,menubar=no,' +
'scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
}
/*
function get_player_reader(filetype)
{
if (filetype == "mov")
{
document.write ('Download the Quicktime viewer');
}
else if (filetype == "pdf")
{
document.write ('Download Adobe Acrobat');
}
else if (filetype == "mpg")
{
document.write ('Download Windows media player');
}
else
{
return true;
}
}
*/