73
Views
4
Comments
recommended way to verify a CSV file

Hi guys, 

I wanted to get your opinion the best way to verify a CSV file.

First option:

1. Create a mapping table that map each column, min length, max length, special char, compulsory

2. Loop through each record and check whether it is TEXT, DECIMAL and DATE. Depending on the type, check the min and max length , special char. For date, check the file format.

Second option:

1. Loop through each record and create multiple IF and hardcode the min length and max length, special char.. Date format as well. If there is changes required, need to recompile.

2023-12-16 19-57-03
Sanjay Kushwah

Hii @Drexxor,

I have also used validation by a mapping table one of my project (sorry I can not provide OML because of the company & client security policies) and it was really easy to maintain and modify so, I would like to recommend Option 1 that is Create a mapping table becuase it provides a centralized location for defining validation rules and makes it easier to manage and modify these rules without recompiling the code.

while hardcoding the rules directly in the code may be easy during implementation but it difficult to maintain and modify them especially when dealing with complex validation logic may be you don't have to deal with complex logic but still is not more future-proof solution.

 Hope this will help you.

Thanks & Regards,

Sanjay Kushwah

UserImage.jpg
Drexxor

Hi Sanjay,

Would you show some sample ?

Using Load2CSV --> with structure like this

Employee

1. Name

2. Age

3. Email

In mapping table,

                         FieldType  MaxLength        RegFormat

Name              TEXT           33                        NULL

Age                  TEXT           2                          NULL

EMAIL              TEXT          255                      --


I have to convert the structure to String so that i can split the string and match to the mapping table since the structure is per ATTRIBUTE. 

Each row of the structure contains the name, age and email while for mapping , 

Each row is different name.

1. I loop through the structure list

2. create a new list 

e.g. vEmployeeList

EmployeeList.Current.EmployeeStruct.NAME + "," + 

EmployeeList .Current.EmployeeStruct.Age + "," +

EmployeeList .Current.EmployeeStruct.EMAIL + "," + 

3. String split vEmployeeList and loop through again.

4.Match each column based on the mapping table.

2023-12-16 19-57-03
Sanjay Kushwah

hii @Drexxor,

inside loop just check your validation rules are satisfying with your value or not by retreive them from DB 

and check 

  // Validate max length  

      if (lenght(EmployeeList.Current.EmployeeStruct.NAME ) > mappingTable.MaxLength ) {

            // Exceeds max length           

               //console.error("Field value exceeds max length for " + fieldName + ": " + fieldValue);

              //show error message

 }else{

      continue.....

}

UserImage.jpg
edgar wang

hi @Drexxor , i have a hosted CSV javascript based validator that can handle any logic. you can share you validation with any ppl so anyone can validate. I can easily handle the requirements of field length, email checks, name checks etc. Let me know if this would be helpful!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.