FastCougar
04-23-2004, 04:55 PM
http://dev.cavlog.com/misc/images/calc2.gif
In the example above, Part1 should be a valid part number even though the item it's validating against has a lower case "p" vs. the value entered, which has an upper case "P". Part2 should be considered invalid since it's not in select box list.
Clicking the “Calculate Estimate” button will run a validation script (code below) to validate that the zip code entered is valid and that the part entered is also valid. I do this by building a string, output from a database (using ColdFusion, thus the <cfoutput> tags in the code below) where each value is seperated by a comma (a list). Since all US ZIP Codes are 5 digits, I don’t have to worry about the search finding "duplicates", or part of the value. However, when using the same methodolgy with the Part Number validation, a problem occurs. "112100" is found because it’s part of Part Number "112100p", "112100US", etc., but 112100 IS NOT a valid part number.
I have overcome this limitation by adding the comma as part of the sub-string that I am searching for, thus making the number unique. Now "112100," is not found in the following string: "112100p,112100US,112100N,...". However, my problem now is that the search() method seems to be case-sensitive. Since the people using the form might not enter the letter portion of part numbers in the proper case. So, a search for "112100P" isn't found in the string "112100p,112100US,112100N,...". I need the search method to run a
case-insensitive search. How would I do this?function ValidateFields() { // Validate all required fields before submitting form
var vTotal = document.frmCalc.TotalPiecesHidden.value;
var validZip = "<cfoutput query='GetVPostalCode'>#postalCode#,</cfoutput>";
var validPart = "<cfoutput query='GetVParts'>#partID#,</cfoutput>";
var vZipCode = document.frmCalc.postalCode.value;
// Validate Postal Code
if (isNaN(vZipCode)) {
alert('Postal Code must be numeric values only.');
document.frmCalc.postalCode.focus();
document.frmCalc.postalCode.select();
return false;
}else{
if (vZipCode.search(/^\d{5}$/)){
alert('Postal Code must be 5 digits.');
document.frmCalc.postalCode.focus();
document.frmCalc.postalCode.select();
return false;
}else{
if (validZip.search(vZipCode) == -1){
alert('Invalid Postal Code, please check and try again.');
document.frmCalc.postalCode.focus();
document.frmCalc.postalCode.select();
return false;
}
}
}
// Validate Part Number
for (i=1; i<=vTotal; i++) {
var vPart = document.frmCalc['Part'+i].value;
if (vPart == ''){
alert("You must enter a part number.");
document.frmCalc['Part'+i].focus();
return false;
break;
}else{
var vPart = document.frmCalc['Part'+i].value + ',';
if (validPart.search(/ivPart/) == -1){
alert('Invalid part number, please check and try again.');
document.frmCalc['Part'+i].focus();
document.frmCalc['Part'+i].select();
return false;
break;
}else{
return true;
}
}
}
}
In the example above, Part1 should be a valid part number even though the item it's validating against has a lower case "p" vs. the value entered, which has an upper case "P". Part2 should be considered invalid since it's not in select box list.
Clicking the “Calculate Estimate” button will run a validation script (code below) to validate that the zip code entered is valid and that the part entered is also valid. I do this by building a string, output from a database (using ColdFusion, thus the <cfoutput> tags in the code below) where each value is seperated by a comma (a list). Since all US ZIP Codes are 5 digits, I don’t have to worry about the search finding "duplicates", or part of the value. However, when using the same methodolgy with the Part Number validation, a problem occurs. "112100" is found because it’s part of Part Number "112100p", "112100US", etc., but 112100 IS NOT a valid part number.
I have overcome this limitation by adding the comma as part of the sub-string that I am searching for, thus making the number unique. Now "112100," is not found in the following string: "112100p,112100US,112100N,...". However, my problem now is that the search() method seems to be case-sensitive. Since the people using the form might not enter the letter portion of part numbers in the proper case. So, a search for "112100P" isn't found in the string "112100p,112100US,112100N,...". I need the search method to run a
case-insensitive search. How would I do this?function ValidateFields() { // Validate all required fields before submitting form
var vTotal = document.frmCalc.TotalPiecesHidden.value;
var validZip = "<cfoutput query='GetVPostalCode'>#postalCode#,</cfoutput>";
var validPart = "<cfoutput query='GetVParts'>#partID#,</cfoutput>";
var vZipCode = document.frmCalc.postalCode.value;
// Validate Postal Code
if (isNaN(vZipCode)) {
alert('Postal Code must be numeric values only.');
document.frmCalc.postalCode.focus();
document.frmCalc.postalCode.select();
return false;
}else{
if (vZipCode.search(/^\d{5}$/)){
alert('Postal Code must be 5 digits.');
document.frmCalc.postalCode.focus();
document.frmCalc.postalCode.select();
return false;
}else{
if (validZip.search(vZipCode) == -1){
alert('Invalid Postal Code, please check and try again.');
document.frmCalc.postalCode.focus();
document.frmCalc.postalCode.select();
return false;
}
}
}
// Validate Part Number
for (i=1; i<=vTotal; i++) {
var vPart = document.frmCalc['Part'+i].value;
if (vPart == ''){
alert("You must enter a part number.");
document.frmCalc['Part'+i].focus();
return false;
break;
}else{
var vPart = document.frmCalc['Part'+i].value + ',';
if (validPart.search(/ivPart/) == -1){
alert('Invalid part number, please check and try again.');
document.frmCalc['Part'+i].focus();
document.frmCalc['Part'+i].select();
return false;
break;
}else{
return true;
}
}
}
}