Validating SA id umbers coding(change view and field)

$(document).on(‘knack-view-render.view_54’, function(event, view, data) {

$("#view_54 .kn-submit input[type=submit]").on(“click”, function validateID(idnum) {


idnum = idnum.toString().replace(" “,”");
r = /^\d{10}[0-1]\d{2}$/;
if (! r.test(idnum)) alert (“Invalid ID Number selected!”);
if (! r.test(idnum)) return false;

n = idnum;
p1 = parseInt(n[0]) + parseInt(n[2]) + parseInt(n[4]) + parseInt(n[6]) + parseInt(n[8]) + parseInt(n[10]);
p2 = (parseInt(n[1] + n[3] + n[5] + n[7] + n[9] + n[11]) * 2).toString();
p3 = 0;
for (i=0; i 9 ? check.toString()[1] : check.toString();
if (check_char != idnum[12]) alert (“invalid ID Number selected!”);
if (check_char != idnum[12]) return false ;

return true;


Tax numbers, I just looked at now. Are you looking to validate only south african tax numbers?

With SA tax numbers it is ZA followed by 10 numbers. Its that simple.

Thanx Shanul!

It’s working!

I also need some coding assistance with a few other validation issues (i.e. tax numbers, etc) - can you give me your email address so that we can discuss support from you offline?

Hi there,

1)Copy and paste the coding from my coding. (attached file)

2)remove my view and field number to what your program goes by.\

3)make sure any other coding is correct as well. When page blank with just a header it means an error in your coding.

*I think the problem with your coding is that you never left lines and the compiler doesnt only read semi colon to read next line. Because when I pasted my coding it got condensed without leaving lines. So I am using an attachment to aid you.

I will look into it on Monday and check it out

Hi Shanul,

Please help!

I am trying to use your code - but obviously doing something wrong - attached is what I see after saving the code.

My idnum field is a Number field.



Is it possible for you to send the attachment again (that you refer to in your message) - I’m trying to use your code to validate SA ID numbers, but it’s not working as it is here.