I have a better idea--use the one from Angular:

https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L11

That's way easier to deal with and good enough here and probably well-tested.