neocool00
08-12-2005, 04:52 PM
I have two database tables that are linked on a 12 digit alphanumeric field (I know that's bad, but I didn't design it and it has to be this way b/c that's how we get the data). Normally, I would just put a drop down for users to select which code that one to associate it, but in this case the lookup table consists of 12,000+ rows. What I am trying to do on the form is to expand my form validation as much as I can so that if the rules for code don't match then the form doesn't get submitted. Let me break down the value of the field:
digits 1 & 2 are numeric.
digit 3 is either 0 or N
digit 4 is a value from another lookup table
digit 5 & 6 are 0s (for now)
The problem I am having is that I want my regular expression to include knowledge of the fourth digit. Currently the values can be C, E, S or T and the administrators of the site have the ability to change those values. So ideally, I want to hit the database to see what values are valid for that field. I know that I could use asp to write out all of the JavaScript to the form and then for that part of the regular expression I could hit the database, but I was hoping for a simpler solution since this is the only part of the form that needs database validation before submitting the form.
This is what I have currently for my validation:
<script language="javascript">
<!--
function validate(theform){
var reCoverageCd1 = /^\d{2}[0N]{1}\w{1}[0]{2}/;
if (theform.coverage_cd1.value == ""){
alert("You forgot to fill in the Coverage Code Box1");
return (false);
}
else if (!reCoverageCd1.test(theform.coverage_cd1.value)) {
alert("You have entered an invalid coverage code in box 1.");
return (false);
}
}
//-->
</script>
digits 1 & 2 are numeric.
digit 3 is either 0 or N
digit 4 is a value from another lookup table
digit 5 & 6 are 0s (for now)
The problem I am having is that I want my regular expression to include knowledge of the fourth digit. Currently the values can be C, E, S or T and the administrators of the site have the ability to change those values. So ideally, I want to hit the database to see what values are valid for that field. I know that I could use asp to write out all of the JavaScript to the form and then for that part of the regular expression I could hit the database, but I was hoping for a simpler solution since this is the only part of the form that needs database validation before submitting the form.
This is what I have currently for my validation:
<script language="javascript">
<!--
function validate(theform){
var reCoverageCd1 = /^\d{2}[0N]{1}\w{1}[0]{2}/;
if (theform.coverage_cd1.value == ""){
alert("You forgot to fill in the Coverage Code Box1");
return (false);
}
else if (!reCoverageCd1.test(theform.coverage_cd1.value)) {
alert("You have entered an invalid coverage code in box 1.");
return (false);
}
}
//-->
</script>