From c20cb6a9b8f61556cf66ba4828c0fb9f246cc7cc Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 6 Feb 2003 08:11:30 +0000 Subject: [PATCH] Added javascript validation functions --- presentation/lookAndFeel/knowledgeTree/js/misc.js | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 163 insertions(+), 26 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/js/misc.js b/presentation/lookAndFeel/knowledgeTree/js/misc.js index 10ba4eb..b4e7890 100644 --- a/presentation/lookAndFeel/knowledgeTree/js/misc.js +++ b/presentation/lookAndFeel/knowledgeTree/js/misc.js @@ -1,30 +1,167 @@ -function validateString(field, msg, min, max) { - if (!min) { min = 1 } - if (!max) { max = 65535 } - - if (!field.value || field.value.length < min || field.value.max > max) { - alert(msg); - field.focus(); - field.select(); - return false; - } - return true; -} - -function validateNumber(field, msg, min, max) { - if (!min) { min = 0 } - if (!max) { max = 255 } - - if ( (parseInt(field.value) != field.value) || field.value.length < min || field.value.length > max) { - alert(msg); - field.focus(); - field.select(); - return false; - } - return true; -} - function setActionAndSubmit(newAction) { document.MainForm.action = newAction; document.MainForm.submit(); } + +function isEmailAddr(email) +{ + var result = false; + var theStr = new String(email); + var index = theStr.indexOf("@"); + if (index > 0) + { + var pindex = theStr.indexOf(".",index); + if ((pindex > index+1) && (theStr.length > pindex+1)) + result = true; + } + return result; +} + +function validRequired(formField,fieldLabel) +{ + var result = true; + + if (formField.value.length == 0) + { + alert('Please enter a value for the "' + fieldLabel +'" field.'); + formField.focus(); + result = false; + } + return result; + +} + +function allDigits(str) +{ + return inValidCharSet(str,"0123456789"); +} + +function inValidCharSet(str,charset) +{ + var result = true; + + // Note: doesn't use regular expressions to avoid early Mac browser bugs + for (var i=0;i 0) && (month < 13) && + allDigits(elems[1]) && (day > 0) && (day < 32) && + allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4)); + } + + if (!result) + { + alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.'); + formField.focus(); + } + } + + return result; +} + +/*function validateForm(theForm) +{ + // Customize these calls for your form + + // Start -------> + if (!validRequired(theForm.fullname,"Name")) + return false; + + if (!validEmail(theForm.email,"Email Address",true)) + return false; + + if (!validDate(theForm.available,"Date Available",true)) + return false; + + if (!validNum(theForm.yearsexperience,"Years Experience",true)) + return false; + // <--------- End + + return true; +}*/ -- libgit2 0.21.4