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' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
forked from: http://getcompiled.net/jquery-validating-australian-abn-numbers-3599909