Skip to content

Instantly share code, notes, and snippets.

@shohagbhuiyan
Last active March 7, 2018 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shohagbhuiyan/d947f025edc6f3b55a97efda71de3e11 to your computer and use it in GitHub Desktop.
Save shohagbhuiyan/d947f025edc6f3b55a97efda71de3e11 to your computer and use it in GitHub Desktop.
Australian Business Number (ABN) format validation for 'jQuery validation'
function abnValidate(value, element){
if (value.length != 11 || isNaN(parseInt(value)))
return false;
var weighting =[10,1,3,5,7,9,11,13,15,17,19];
var tally = (parseInt(value[0]) - 1) * weighting[0];
for (var i = 1; i < value.length; i++){
tally += (parseInt(value[i]) * weighting[i]);
}
return (tally % 89) == 0;
}
jQuery.validator.addMethod(
'abnValidate',
abnValidate, 'This ABN is not valid'
);
@shohagbhuiyan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment