Australian Business Number (ABN) format validation for 'jQuery validation'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
forked from: http://getcompiled.net/jquery-validating-australian-abn-numbers-3599909