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
https://forums.phpfreaks.com/topic/101970-simple-form-validation/
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;
		}
	} 

Archived

This topic is now archived and is closed to further replies.

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