tags:

views:

29

answers:

2

I have a 2 column in my subscriber table.

Name | email

I want to import a CSV file data in respective column with validation of email column.

I have done uploading CSV part, but i don't know how to insert data with email validation.

How I can do this, I have search allover net but I can't find any working answer on it.

Please help

A: 

You can do it in two ways:

  1. Insert all the data into the table (which can easily be done with mysql itself) and then read and validate the data with PHP using regular expressions.
  2. Use PHP to read the CSV, validate the email and only if valid, insert them into the table

Some basic email regex can be found here: http://regexlib.com/Search.aspx?k=email

Kau-Boy
+1  A: 

For validating the email you could use preg_match() with an email pattern like ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$ (see regex).

StefanMacke