title: Validate content of csv file c#
body: <p>I have a requirement where user will be uploading a csv file in the below format which will contain around 1.8 to 2 million records</p>
  
  <pre><code>SITE_ID,HOUSE,STREET,CITY,STATE,ZIP,APARTMENT  
  44,545395,PORT ROYAL,CORPUS CHRISTI,TX,78418,2  
  44,608646,TEXAS AVE,ODESSA,TX,79762,  
  44,487460,EVERHART RD,CORPUS CHRISTI,TX,78413,  
  44,275543,EDWARD GARY,SAN MARCOS,TX,78666,4  
  44,136811,MAGNOLIA AVE,SAN ANTONIO,TX,78212  
  </code></pre>
  
  <p>What i have to do is, first validate the file and then save it in database iff its validated successfully and has no errors. The validations that i have to apply are different for each column. For example,</p>
  
  <pre><code>SITE_ID: it can only be an integer and it is required.  
  HOUSE: integer, required  
  STREET: alphanumeric, required  
  CITY: alphabets only, required  
  State: 2 alphabets only, required  
  zip: 5 digits only, required  
  APARTMENT: integer only, optional  
  </code></pre>
  
  <p>I need a generic way of applying these validations to respective columns. What i have tried so far is that i converted the csv file to dataTable and i plan to try and validate each cell through regex but this doesn't seem like a generic or good solution to me. Can anyone help me in this regard and point me to the right direction?</p>