Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining edits syntax help needed

Status
Not open for further replies.

techexpressinc

Programmer
Oct 28, 2008
67
US
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>
 
You have declared lengthRestriction with 3 params and you invoke it with 4.

There might be more errors. A detailed description of them will help.

Cheers,
Dian
 
Dian - that 4th parameter is ignored thx for pointing it out I should clean-up the code.

The problem is I what both edits. Length and Numeric checks. This code snapshot does the length but not the numeric. I can not seem to get the edits coded to both happen. I have tried for a couple hrs.

Russ
 
Fixed below is the working code!
.style14 {
text-align: center;
}
</style>


<script type="text/javascript">
function formValidator(){
var zip = document.getElementById('ZipCode').value;
if (/^\d{5,9}$/.test(zip)) { return true; }
else
alert("Please enter a valid zipcode between 5 and 9 characters");
return false;
}
</script>





</head>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top