On Import of CSV, basic data validation

On Import of CSV, basic data validation

bfarkasbfarkas Posts: 181Questions: 48Answers: 0

I am trying to think of a good way to do some basic validation, such as a simple regex edit on a phone field to eliminate all non-number characters, while the data is being brought into the table. Since these are multi-edits, it would need to just edit the offending data, so keeping them basic is key and fine.
Anyone have a good idea for how to approach or an example doing anything like this?

Answers

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Thinking about this more, I am wondering if i should do it as a function that is run anytime rows are added to the table, and then I can be column specific, which makes it a bit universal and eliminates the complexity from different types and orders of data coming in.

    So it would be a matter of whenever a new row is entered regardless of addition method running a check like below on specific cells by column:

    var tel = new.cell.value;
            tel = tel.replace(/\D+/g, "").replace(/^[01]/, "");
            this.value = tel;
    
    
  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Thinking I can do something like this on the preCreate event, and fortunately with the import process, a separate editor is being used, so can define the rules for just that editor no?

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    I think progress. I am doing this:

    p200GcsvImporter.on('preCreate', function(e, json, data) {
        var checkPhone = data['home_phone']
        var newPhone = checkPhone.replace(/\D+/g, "").replace(/^[01]/, "");
        data['first_name'] = newPhone;
      })
    

    But it seems the value i snot being passed into the function. I think i am selecting incorectly for the checkPhone variable. What am i missing?

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Nvmd, this is working now. I was mapping the wrong field from my csv file during the test.

This discussion has been closed.