techexpressinc
Programmer
I have Two edits I want to do on the zip code field. I can get them to work independently. But, I can not get the syntax right to have both edits working. Below is the code with the length one working. I want to add the numeric edit too. Can someone help me get the syntax right, I have spend over 2 hrs. trying. Thank you Russ Rneuman @ scaninc.org
<script type='text/javascript'>
function formValidator(){
// Make quick references to our fields
var zip = document.getElementById('ZipCode');
// Check each input
if(lengthRestriction(zip,5,9, "Please enter a valid zip code")){
return true;
}else{
return false;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
alert("Please enter between " +min+ " and " +max+ " characters");
}else{
alert("Please enter between " +min+ " and " +max+ " characters");
elem.focus();
return false;
}
}
}
</script>
<script type='text/javascript'>
function formValidator(){
// Make quick references to our fields
var zip = document.getElementById('ZipCode');
// Check each input
if(lengthRestriction(zip,5,9, "Please enter a valid zip code")){
return true;
}else{
return false;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
alert("Please enter between " +min+ " and " +max+ " characters");
}else{
alert("Please enter between " +min+ " and " +max+ " characters");
elem.focus();
return false;
}
}
}
</script>