Deluge script not working for validating a single line field

Deluge script not working for validating a single line field

Good day,

I have created a function to validate a field in the contacts module. However, it doesn’t seem to be working and I can not find the reason. 

In South Africa, our unique identification number is a ID Number. I am using that as the unique identifier for our Contacts module. However, we do have non South African clients as well, for which we want to use their passport numbers. 

The field ID Number (Single Line) must be validated according to the two options only. 

See script below:

contactdetails = zoho.crm.getRecordById("Contacts",contactId);
contid = contactdetails.get("ID_Number");
// Replace with the actual field name
if(contid.length() == 13)
{
if(contid.substring(0,2).matches("\\d{2}") && contid.substring(2,4).matches("\\d{2}") && contid.substring(4,10).matches("\\d{6}") && contid.substring(10).matches("[\\dA-Z]{10}"))
{
result = "South African ID number";
}
else
{
result = "Invalid input";
}
}
else if(contid.length() == 9)
{
if(contid.substring(0,2).matches("[A-Z]{2}") && contid.substring(2).matches("\\d{7}"))
{
result = "South African Passport number";
}
else
{
result = "Invalid input";
}
}
else
{
result = "Invalid input";
}
info result;


Kindly advise why you think it is not working.

Regards