Nomvula Posted September 30, 2003 Posted September 30, 2003 hi guys could you please help me I've done my script checking for input data but now I have a problem including checking for number validation in Postal Code field: here's my code and on the Postal code instead of checking for empty field I need to change it to validate number only: function isformvalid() { //Load Vars from form txtFirst_Name = document.frmValidate.txtFirst_Name.value; //alert(txtFirst_Name); txtSurname= document.frmValidate.txtSurname.value; txtEmail= document.frmValidate.txtEmail.value; txtPostal_Code= document.frmValidate.txtPostal_Code.value; msgHeader = "The form contains the following errors:\n\n"; errMsg = ""; numErrors = 0; var focusElement; //First Name if(txtFirst_Name==""){ errMsg += "Your first name is required,\n"; if(focusElement == null) focusElement = document.frmValidate.txtFirst_Name; document.getElementBy("firstNameError").className= "show"; numErrors = numErrors + 1; } else { document.getElementBy("firstNameError").className= "hide"; } //Surname if(txtSurname==""){ //alert("here"); errMsg += "Your Surname is required,\n"; if(focusElement == null) focusElement=document.frmValidate.txtSurname; document.getElementById("surnameError").className = "show"; numErrors = numErrors + 1; } else { document.getElementById("surnameError").className = "hide"; } //Email if(txtEmail==""){ //alert("here"); errMsg += "Your Email is required,\n"; if(focusElement == null) focusElement = document.frmValidate.txtEmail; document.getElementById("EmailError").className = "show"; numErrors = numErrors + 1; } else { document.getElementById("EmailError").className = "hide"; } //Postal Code if(txtPostal_Code==""){ errMsg += "Enter Postal Code is required.\n"; if(focusElement == null) focusElement = document.frmValidate.txtPostal_Code; document.getElementById("CodeError").className = "show"; numErrors = numErrors + 1; } else { document.getElementById("CodeError").className = "hide"; } //Check to see if we had any errors if(numErrors>0){ alert(msgHeader + errMsg); if(focusElement) focusElement.focus(); return false; }else{ return true; } } --> </script> Quote
BlueJay924 Posted September 30, 2003 Posted September 30, 2003 i'm not sure if this helps you but i normally use this to check for numbers: If ZipcodeBox.Text = "" Or (oRegex.IsMatch(ZipcodeBox.Text, "\d{5}") And ZipcodeBox.Text.Length = 5) Then 'then this is a valid zipcode else 'not valid end if i've only done this for a 5 digit zip code. accepts only numbers. Quote
*Experts* Volte Posted September 30, 2003 *Experts* Posted September 30, 2003 What language is this? This looks like some form of JavaScript to me. Quote
Nomvula Posted October 2, 2003 Author Posted October 2, 2003 thanks, but I need to check for four digits and it must be only numbers Quote
BlueJay924 Posted October 2, 2003 Posted October 2, 2003 if you're using vb.net it should work. just change where is 5 to 4. and it does check to make sure that the characters entered are numbers. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.