Guide to the TechWeb Network

Intelligent Enterprise

Better Insight for Business Decisions

Intelligent Enterprise - Better Insight for Business Decisions
search Intelligent Enterprise
Advanced Search
RSS
Webcasts
Whitepapers
Subscribe
Home



Celko's Email-Address-Validation SQL Puzzle | Intelligent Enterprise Blog
Celko's Email-Address-Validation SQL Puzzle

Posted by Joe Celko
Monday, September 17, 2007
7:26 AM

You've probably noticed that many Web sites use the customer's email addresses as an identifier — an email address has a very easy validation. We have all received messages something like this: "Thanks for signing up for 'The Leech Farmer's Monthly' email newsletter! We are sending you a confirmation at your email address with your temporary password."

How many ways can you write CHECK() column constraint to validate an email address? Call the column "email" just so all entries look alike (yes, you really should use "_email" to follow ISO-11179 rules). You are not allowed to do an external function call; it has to be in Standard SQL or a dialect extension.

Standard SQL has a regular expression called the SIMILAR TO predicate which is based on the POSIX standards. Likewise, SQL Server has extensions to the LIKE predicate; Oracle has a function call, and so forth for other vendors. These are the obvious (and probably the fastest) answers in each dialect.

Hint #1: Google up a regular expression site and look at grep() family versions for solutions.

Hint #2: You know that you have to have a single @ in the string, but did you remember that the postfix can be a country ISO code, or a three-letter domain?

Hint #3: Do you know where the letters, digits and special symbols can and cannot be found in the email string? Do you know what special symbols are allowed?

I'll post my answer to this puzzle next week. In the meantime, post your entry in the comment field below and I'll send the first respondent offering three valid approaches a free copy of one my books on SQL.

Plus, don't miss this month's "Celko on SQL" column, "Natural, Artificial, Exposed and Surrogate Keys Explained."

Joe Celko is an independent consultant in Austin, Texas, and the author of SQL Puzzles and Answers (2006), Joe Celko's SQL for Smarties: Advanced SQL Programming (2005), and Joe Celko's Trees and Hierarchies in SQL for Smarties (2004).



E-MAIL | SLASHDOT | DIGG




This is a public forum. CMP Technology and its affiliates are not responsible for and do not control what is posted herein. CMP Technology makes no warranties or guarantees concerning any advice dispensed by its staff members or readers.

Community standards in this comment area do not permit hate language, excessive profanity, or other patently offensive language. Please be aware that all information posted to this comment area becomes the property of CMP Media LLC and may be edited and republished in print or electronic format as outlined in CMP Technology's Terms of Service.

Important Note: This comment area is NOT intended for commercial messages or solicitations of business.


 




    Subscribe to RSS


 



techweb
Online Communities TechWebInformationWeekLight ReadingIntelligent EnterprisebMightyNetwork ComputingDark ReadingDigital LibraryWall Street & Technology
Byte & SwitchNo JitterInternet EvolutionLight Reading's Cable Digital NewsContentinopleUnStrungBank Systems & TechnologyAdvanced TradingInsurance & Technology
Face-to-Face Events
InteropWeb 2.0 ExpoWeb 2.0 SummitVoiceConBlack HatCSISoftwareEntrprise 2.0 ConferenceGTEC
Mobile Business Expo
InformationWeek 500 ConferenceBuy Side Trading XchangeBuy Side Trading SummitBank Executive SummitInsurance Executive SummitTelcoTVEthernet ExpoOptical Expo
Magazines  
InformationWeekWall Street & TechnologyInsurance & TechnologyBank Systems & TechnologyAdvanced TradingMSDNTechNetSmart EnterpriseThe Architecture JournalDatabase Magazine
 
Research & Analyst Services  
Heavy ReadingInformationWeek ReportsInformationWeek Analytics