Computer
Roku Makes 2FA Mandatory For All After Nearly 600K Accounts Pwned
Read more of this story at Slashdot.
Linus Torvalds Injects Tabs To Thwart Kconfig Parsers Not Correctly Handling Them
Read more of this story at Slashdot.
A D&D Actual Play Show Is Going To Sell Out Madison Square Garden
Read more of this story at Slashdot.
Crickets From Chirp Systems in Smart Lock Key Leak
Read more of this story at Slashdot.
Stanford Releases AI Index Report 2024
Read more of this story at Slashdot.
Ubisoft Revokes Access To Purchased Game, Sparking Digital Ownership Debate
Read more of this story at Slashdot.
UK Starts Drafting AI Regulations for Most Powerful Models
Read more of this story at Slashdot.
Song Lyrics Have Become Simpler and More Repetitive Over the Last Five Decades
Read more of this story at Slashdot.
Security Engineer Jailed For 3 Years For $12M Crypto Hacks
Read more of this story at Slashdot.
Senator Warren Claims TurboTax 'Relentlessly' Upsells Customers in Letter To FTC
Read more of this story at Slashdot.
Sony's PS5 Pro is Real and Developers Are Getting Ready For It
Read more of this story at Slashdot.
iOS App Store's First Game Boy Emulator Taken Down Just Days Later
Read more of this story at Slashdot.
Telecom Fights Price Caps as US Spends Billions on Internet Access
Read more of this story at Slashdot.
Apple Loses Mantle as World's Biggest Phone Seller To Samsung as China Sales Drop
Read more of this story at Slashdot.
Emissions Dropped 1.8% Every Year in California's Bay Area. Researchers Credit EVs
Read more of this story at Slashdot.
Disneyland Adds 'Stars Wars' Touches (and New Droids) for 'Season of the Force' Event
Read more of this story at Slashdot.
CodeSOD: A Top Level Validator
As oft stated, the specification governing email addresses is complicated, and isn't really well suited for regular expressions. You can get there, but honestly, most applications can get away with checking for something that looks vaguely email like and call it a day.
Now, as complicated as the "accurate" regex can get, we can certainly find worse regexes for validating emails. Morgan did, while on a contract.
The client side had this lovely regex for validating emails:
/* Check if a string is in valid email format. Returns true if valid, false otherwise. */ function isEmail(str) { var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i; return regex.test(str); }They check a long list of TLDs to ensure that the email address is potentially valid, or accept an email address. Is the list exhaustive? Of course not. There are loads of TLDs not on this list- perhaps not widely used ones, but it's incomplete. And also, unnecessary.
But not so unnecessary that they didn't do it twice- they mirrored this code on the server side, in PHP:
function isEmail($email) { return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i" ,$email)); }Bad code is even better when you have to maintain it in two places and in two languages. I suppose I should just be happy that they're doing some kind of server-side validation.
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!California Replaces Gas Plant with Giant, Billion-Dollar Grid Battery
Read more of this story at Slashdot.
CNN Reporter 'Still Haunted' By Space Shuttle Columbia Disaster
Read more of this story at Slashdot.
America's Legal System May Be 'Closing In' on Regulating Cryptocurrencies
Read more of this story at Slashdot.