Skip to content

Instantly share code, notes, and snippets.

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 mansfeldpl/d9c403752a35f2849efade944fe7fa17 to your computer and use it in GitHub Desktop.
Save mansfeldpl/d9c403752a35f2849efade944fe7fa17 to your computer and use it in GitHub Desktop.
NIP (Polish Tax number) jQuery Validation
<form id="form">
<input type="text" name="nip" id="nip" placeholder="NIP" required>
<input type="reset" name="reset" value="Reset" class="wyslij" style="background-color:#fff;"><input type="submit" name="submit" value="Wyślij" class="wyslij" style="background-color:#fff;">
</form>

NIP (Polish Tax number) jQuery Validation

In this Pen I'll show you simple algorithm to check if NIP (Polish Tax Number) is correct or not.

A Pen by Paweł Mansfeld on CodePen.

License.

$("#nip").change(function(){
var currentnip = $("#nip").val().replace(/\D/g,"");
$(this).val(currentnip);
});
$("#form").submit(function(){
var nip = $("#nip").val();
var nipsum = parseInt(nip.charAt(0))*6+parseInt(nip.charAt(1))*5+parseInt(nip.charAt(2))*7+parseInt(nip.charAt(3))*2+parseInt(nip.charAt(4))*3+parseInt(nip.charAt(5))*4+parseInt(nip.charAt(6))*5+parseInt(nip.charAt(7))*6+parseInt(nip.charAt(8))*7;
reszta = nipsum % 11;
if(reszta == parseInt(nip.charAt(9))){
alert("NIP poprawny!");
}
else{
alert("NIP niepoprawny");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment