Jump to content

Simple form validation


chet139

Recommended Posts

Hi,

 

Im using javascript for some basic form validations here what I have so far and it works:

 

function checkFields() //validation to ensure at least one field is populated
	{
	//
		if(cust.custId.value != "" && cust.custTitle.value != "" && cust.custFirstname.value != "" && cust.custSurname.value != "" && cust.propNo.value != "" && cust.propStreet.value != "" && cust.propTown.value != "" && cust.propCounty.value != "" && cust.propPostcode.value != "")  
		{
			return true;

		}

		else 
		{
		alert("Please Enter the Details");
		return false;
		}
	}

 

However to this, I would like to add a check for checking the CUSTID id numeric only.I am trying to use the isNAN function somehow but have had no success can anyone help please? For example i tried adding to the end of my IF statement "&& isNAN(cust.custId.value)==false" so if its false the overall check passes. because I want it numeric only whereas isNAn checks if its not numeric.

Link to comment
Share on other sites

Try this it might work, logically it shoud

 

 

function checkFields() //validation to ensure at least one field is populated
	{
	var onlyNumbers =isNAN(cust.custId.value);
	//
		if((cust.custId.value != ""&& onlyNumbers=="false") && cust.custTitle.value != "" && cust.custFirstname.value != "" && cust.custSurname.value != "" && cust.propNo.value != "" && cust.propStreet.value != "" && cust.propTown.value != "" && cust.propCounty.value != "" && cust.propPostcode.value != "")  
		{
			return true;

		}

		else 
		{
		alert("Please Enter the Details");
		return false;
		}
	} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.