CodeSOD: Top Level Validator

As is often stated, the specification governing email addresses is complicated and not well suited for regular expressions. You can get there, but honestly, most apps can get away with checking something that looks vaguely like email and be done with it.

Now, as complicated as a “precise” regular expression might be, we can certainly find worse regular expressions for email verification. Morgan did, while he was on contract.

The client side had this nice regular expression for email validation:

/*
Check if a string is in valid email format.
Returns true if valid, false otherwise.
*/
function isEmail(str)
af

They check a long list of TLDs to ensure that the email address is potentially valid or accept the email address. Is the list exhaustive? Of course not. There are tons of TLDs that aren’t on this list – maybe ones that aren’t widely used, but it’s incomplete. And also, unnecessary.

But not so unnecessary that they didn’t do it twice – they copied this code on the server side, in PHP:

function isEmail($email)
bo

Bad code is even better when you have to maintain it in two places and in two languages. I guess I should be happy they do some a type of server-side validation.

[Advertisement]

Use BuildMaster to release your software with confidence, at the pace your business demands. Download today!

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *