Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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>

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...