开发者

Import CSV file in mysql with email validation

I have a 2 column in my subsc开发者_JAVA技巧riber 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


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜