JavaScript email address validation part 2

A few people have responded to yesterday's post about validating email addresses in JavaScript pointing out that it's very very wrong. For starters, Skud points out that .info addresses won't work. Howie points out .mobi and further, .museum being valid domains.

Stephen Thorne was most scathing, and has very good points to say.

For a start, ' is valid in email addresses, but not at the beginning or the end, O'Brian@example.com. That's just a simple real-world case and ignores the perfectly valid myname@[59.167.98.48], email addresses with doublequotes and spaces, the myriad ways of escaping, etc. RFC821 has a full grammar for email addresses.

The best possible way to validate an email address is to ask the MX for that domain if you can deliver mail there. Can't be done in javascript without ajax of course, but it's probably the best way. You do the "HELO/MAIL FROM: <>/RCPT TO: $username" handshake with the mx, and if it doesnt' reject you, you know it's at least partway valid.

Otherwise, your best bet is to check that it contains an @ and is more than 4 characters. Anything in between will reject valid email addresses.

I suppose what this results in is that you want 1 or more characters left of the @, then three or more characters to the right, with at least one period. The right-hand side you can constrain a bit more, since the acceptable characters for domains are easily defined.

And yes, myname@[59.167.98.48] is a valid SMTP addressee, but I'm not sure I'd call it an email address in the modern sense any more than I'd expect bang paths.

I'll work up a regex implementing what I outlined above shortly, though I've got a higher-priority project for today so it'll probably be tomorrow. Thanks for the feedback!

PS: RFC2821 supersedes 821.

PPS: Both Skud and Stephen wanted a way to comment on my blog. I don't have the time nor energy to spend 45 minutes de-spamming my blog, which is why I put a "contact me" link on it, which points to my mail form.

Be sure to see this followup.

JavaScript regex for email address validation

I found this helpful page with a nice recipe for email address validation in JavaScript. Unfortunately the regular expression doesn't allow for email addresses with a plus sign in the front part, for example foo+bar@argle.com. These kinds of email addresses are perfectly valid and are used by many to implement disposable email addresses (though I'd recommend Sneakemail myself).

So here's my amended regular expression for validating email addresses. Have I missed anything?

^\w(?:\w|-|\.|\+(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}

Before you use this, you might want to read my follow up post with comments from a number of people on the unsuitability of this pattern.

Simon and Holly: greengrocers to the stars

Our dining
room, full of fruit and veg

We're in this little fruit and veg co-op with a bunch of mates. Our turn to head out early in the morning to Flemington came up, and here's all the veg divided up. It's a great time for produce, with a huge variety in peak condition at really cheap prices. We didn't manage to spend all the $30 per household budget before filling the little car.

A DVD player that doesn't suck?

DVD players seem to be disposable devices these days. You really only get a year out of one before it starts randomly skipping on brand new discs. So I'm in the market for a new one.

This time around, I'd like one that doesn't insist on following the studio's instructions. When I press the "root menu" button, I don't want to be told "Operation not allowed by disc" given that I own both the disc and player.

So does such a device exist? Are there DVD players that obey their owners?

NYE 2008 and housewarming

Margaret
and Nathan

The party at our new place last night was loads of fun. Stretching across twelve hours, a bunch of people tramped through the house, got drunk, danced and shouted at each other. Great fun!

I took some photos.

Tags
Posted

Laminate flooring and Udden bench and drawers

Before

Today we got a lot done on the house. We laid a laminate floor in the kitchen and built an Udden bench with drawers. Above is the "before" shot. Note the disgusting lino and the oh-so-chic bachelor pad cum ski lodge wood-panelled cupboards. We ripped up the lino and pulled out the cupboards.

Sun Herald
27th January 1980

We found this nugget of history under the lino. January 27 1980. The Sunday Herald hasn't changed, with its screaming headline about us selling Titanium ore to the reds, while we couldn't sell wheat to them because they invaded Afghanistan. Underneath Macca is getting deported from Japan for forming Wings. Or something.

Underlay
and flooring go down

The underlay and flooring go down.

The trim
goes down

The trim goes down, to hide my sins.

The
finished kitchen

And here it is finished, with the Udden bench and drawers. Lovely!

Lessons learnt: Measure twice, cut once is very optimistic. More like measure twice, get someone else to check your measurements, stop and have a think, measure again, then cut. Sometimes you get it right.

But this laminate flooring is great. We bought a very cheap type of it, as we plan to completely redo the kitchen soon enough anyway. All up it probably cost about $120, including some tools I had to buy.

I took a bunch more photos too.

Next job is fixing shelves and stuff to the walls.

Tags
Posted

Productive DIY day

Four bikes
on racks

I'm starting a new category, DIY, to capture improvements we're making around the house.

I had a very productive day of DIY yesterday. I made and installed a couple of flyscreens for our bedroom and the lounge room. Flyscreens are amazingly simple to make. All you need is a hacksaw, mitre box and a special tool for stuffing the spline into the slot which costs about two bucks. All the materials for the screens themselves can be bought at your local hardware store. The most important thing, though, is to get your measurements right. Geometric transformations in your head, the classic tool of IQ tests, are needed to ensure you're cutting the aluminium in the right direction.

After the screens we grabbed four bike storage hooks from Cell Bikes down on Parramatta Road and I installed them. This allows us to store our four bikes in a very small space. Hanging from the front wheel isn't ideal, but we need the space. I made a bit of a mess of the wall getting the holes drilled with my crappy non-hammer cordless drill, but once we get a shed built we'll repaint the room anyway.

Kitchen
before the makeover

The next project will happen tomorrow. We've bought some laminate flooring and a bunch of Ikea shelves. The laminate needs to acclimatise to the kitchen for two days, so that means we can't lay it until tomorrow lunchtime.

Apart from the floor and all the shelves, the crappy cupboard and bench in the middle there is coming out to be replaced with the Udden stainless steel console we've already got, supplemented with two drawer units. With those drawers and all the shelves, we should find ourselves with much more kitchen space and certainly it'll be a lot nicer.

Tags
Posted

Wall fastening

A question for any DIYers out there. I'm going to be installing an Udden shelf tomorrow and I'm wondering what kind of fastening to use. Ikea are very coy in their instructions: "Choose screws and fittings that are specially suited to the material in your wall/ceiling and have sufficient holding power." Which isn't very helpful.

I was thinking of using green wall plugs and 10G x 50mm screws but that shelf only has four screw holes, which would place quite a bit of load on such fixings. I've been trying to find some specs on what you can load on such screws, without much success. Given that we'll probably be storing glases and plates on it, I'd want something that's well and truly strong enough.

Should I consider one of the more technical fixings like Dynabolts and similar? There are varieties that don't seem to need special tools, and their web site gives excellent technical and installation information, not that I know how to interpret the technical specs.

Suggestions?

Tags
Posted