>
0:00 0 0
ABN validator for Australia

ABN validator for Australia

  DrUalcman |  Julio 262019

Here have a simple functions to validate the ABN for Australian's trade. This validator is for calculate if the ABN number is correct or not. I create a function in JAVASCIPT and C#. I hope help you in some codes.

C# version

    /// 
/// Check if the ABN number is correct
///

/// number to check.
///
public static bool Abn_Validator(string ABN)
{
bool retorno;
ABN = ABN.Trim().Replace(" ", "");
if (ABN.Length == 11)
{
try
{
Int64 number;
number = Convert.ToInt64(ABN);

char[] numeros = ABN.ToArray();
int[] control = new int[11];
control[0] = (Convert.ToInt32(numeros[0].ToString()) - 1) * 10;
control[1] = Convert.ToInt32(numeros[1].ToString());
control[2] = Convert.ToInt32(numeros[2].ToString()) * 3;
control[3] = Convert.ToInt32(numeros[3].ToString()) * 5;
control[4] = Convert.ToInt32(numeros[4].ToString()) * 7;
control[5] = Convert.ToInt32(numeros[5].ToString()) * 9;
control[6] = Convert.ToInt32(numeros[6].ToString()) * 11;
control[7] = Convert.ToInt32(numeros[7].ToString()) * 13;
control[8] = Convert.ToInt32(numeros[8].ToString()) * 15;
control[9] = Convert.ToInt32(numeros[9].ToString()) * 17;
control[10] = Convert.ToInt32(numeros[10].ToString()) * 19;

int total = 0;
for (int i = 0; i < 11; i++)
{
total += control[i];
}

if (total % 89 == 0) retorno = true;
else retorno = false;
}
catch
{
retorno = false;
}
}
else retorno = false;

return retorno;
}

JAVASCRIPT version

	function Abn_Validator(myAbn)
{
let retorno = false;
let ABN;
try {
ABN = myAbn.value;
} catch (e) {
ABN = '';
}
if (ABN.length == 11) {
try {
let control = new Array(11);
control[0] = (convert2integer(ABN[0],false) - 1) * 10;
control[1] = convert2integer(ABN[1], false);
control[2] = convert2integer(ABN[2], false) * 3;
control[3] = convert2integer(ABN[3], false) * 5;
control[4] = convert2integer(ABN[4], false) * 7;
control[5] = convert2integer(ABN[5], false) * 9;
control[6] = convert2integer(ABN[6], false) * 11;
control[7] = convert2integer(ABN[7], false) * 13;
control[8] = convert2integer(ABN[8], false) * 15;
control[9] = convert2integer(ABN[9], false) * 17;
control[10] = convert2integer(ABN[10], false) * 19;
let total = 0;
for (let i = 0; i < 11; i++)
{
total += control[i];
}

if (total % 89 == 0) retorno = true;
else retorno = false;
}
catch
{
retorno = false;
}
}
else retorno = false;
return retorno;
}

That's all. Happy coding

#CSHARP, #javascript, #utilidades

0 Comentarios

 
 
 
>

Archivo