Australian Postcode Validation Function

entityMap = crmAPIRequest.toMap().get("record");
response = Map();
/* ---------------------------------------------------------------------------------------------- */
postcode = entityMap.get("Billing_Code");
state = entityMap.get("Billing_State");
//Ensure that the State
if(!isnull(state))
{
	if(!isnull(postcode))
	{
		//Regex to check postcode format matches 4 digits
		if(postcode.matches("[0-9]{4}"))
		{
			//ensure that postcode is a number for the operator functions and will remove any leading 0's
			postcode = postcode.toNumber();
			//ACT
			if(state == "ACT")
			{
				if(postcode >= 200 && postcode <= 299 || postcode >= 2600 && postcode <= 2618 || postcode >= 2900 && postcode <= 2920)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//NSW
			else if(state == "NSW")
			{
				if(postcode >= 1000 && postcode <= 2599 || postcode >= 2618 && postcode <= 2899 || postcode == 3644 || postcode == 3707)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//VIC
			else if(state == "VIC")
			{
				if(postcode >= 3000 && postcode <= 3999 || postcode >= 8000 && postcode <= 8999)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//QLD
			else if(state == "QLD")
			{
				if(postcode >= 4000 && postcode <= 4999 || postcode >= 9000 && postcode <= 9999)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//SA
			else if(state == "SA")
			{
				if(postcode >= 5000 && postcode <= 5999)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//TAS
			else if(state == "TAS")
			{
				if(postcode >= 7000 && postcode <= 7999)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//WA
			else if(state == "WA")
			{
				if(postcode >= 6000 && postcode <= 6999)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			//NT
			else if(state == "NT")
			{
				if(postcode >= 800 && postcode <= 999)
				{
					response.put('status','success');
				}
				else
				{
					response.put('status','error');
					response.put('message','This postcode does not belong to this state.');
				}
			}
			else
			{
				response.put('status','error');
				response.put('message','Please enter state in the following format: NSW, VIC, SA.');
			}
		}
		else
		{
			response.put('status','error');
			response.put('message','Postcode must be a 4 digit number.');
		}
	}
	else
	{
		response.put('status','error');
		response.put('message','Please enter a postcode.');
	}
}
return response;