I'm trying to validate VAT Codes entered into a form.
Whats the best way of checking the contents of a form input? For example, Austria's VAT code has the standard template of "U12345678" (a "U" followed by 8 numbers) and I want to check that the first character of the input value is "U"
Has anyone got any ideas?
My current Javascript is:
BTW, the country selection works fine and the length is detected fine.Code:var co = document.frmPayment.country.value; var vatcode = document.frmPayment.VATCode.value; var vatfirst = left(vatcode, 1); var vatlen = vatcode.length; alert("Country = '" + co + "'\nVAT Code = '" + vatcode + "'\nVAT Length = '"+ vatlen + "'\nFirst Character = " + firstchar + "'"); if (co=='040' || co=='056' || co=='620' || co=='208' || co=='246' || co=='442' || co=='250' || co=='276' || co=='300' || co=='372' || co=='380' || co=='528' || co=='724' || co=='752') { // if any of the VAT code countries are selected if (vatlen==0) { alert("Please enter your VAT code"); document.frmPayment.VATCode.focus(); return false; } else { if (co == '040') { // if the country is austria if (vatfirst != 'U') { alert ("Please enter a valid VAT code.\n\n Eg. U12345678"); document.frmPayment.VATCode.focus(); return false; } } } }
Cheers,





Bookmarks