Search code examples
emailazure-sql-databasevarcharnvarchar

What SQL column data type should be used to store email addresses?


What SQL column data type should be used to store email addresses? I'm thinking varchar(256) is probably the answer. Is there any reason it should be nvarchar(256)? I'm writing to a SQL Azure database.

How can I do client-side validation of email addresses to find out whether the user has typed a unicode character or not?


Solution

  • Email addresses are allowed to have non-Unicode characters: Are email addresses allowed to contain non-alphanumeric characters?

    I would as a best practice create an nvarchar column for globalization/localization support in the future (because you never know). The extra space required for an nvarchar versus a varchar is very negligible.

    As far as capturing every possible character for email validation is not easy, you could write a regex function to check for this as most high level languages are Unicode compliant.