Last active
January 10, 2018 08:52
-
-
Save tesshsu/431983a5a9d9b7c2e35ed34411b01a50 to your computer and use it in GitHub Desktop.
VAT regular Expresion
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
jQuery("form#adminForm, form#userForm").on("submit", function(event) { | |
var isTva = true; | |
var inputsTva = jQuery('form#adminForm #pluginistraxx_euvatchecker_field'); | |
// define reg part, each country code has match different quantifier | |
// for example, GB matches the characters GB literally (case sensitive), matches a digit 0-9, Matches exactly 5 times | |
var regTva = /^(RO\d{2,10}|GB\d{5}|GBGD\d{3}|CHE\d{9}|CZ\d{8,10}|(ATU|DK|FI|HU|LU|MT|SI)\d{8}|IE[A-Z\d]{8}|(DE|BG|EE|EL|LT|BE0|PT)\d{9}|CY\d{8}[A-Z]|(ES|GB)[A-Z\d]{9}|(BE0|PL|SK|RU)\d{10}|(FR|IT|LV)\d{11}|(LT|SE)\d{12}|(NL|GB)[A-Z\d]{12})$;/g; | |
//bind each related tva input, if not pass reg, return false | |
jQuery.each(inputsTva, function(){ | |
if(!regTva.test(jQuery(this).val())) { | |
isTva = false; | |
} | |
}); | |
// if return false disable submit button and alert message | |
if (!isTva) { | |
event.preventDefault(); | |
alert('PLease fill in correct TVA numbers.'); | |
jQuery(this).prop('disabled', true); | |
}else { | |
jQuery(this).prop('disabled',false); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment