Validate fields tables

When I want to validate fields of a table, especially identification documents, I am using this code, but I am trying to optimize it, I accept suggestions.
I use the positions of the fields to be able to validate.

Method using JS: