Can I determine if a string is a MongoDB ObjectID?

I found that the mongoose ObjectId validator works to validate valid objectIds but I found a few cases where invalid ids were considered valid. (eg: any 12 characters long string) var ObjectId = require(‘mongoose’).Types.ObjectId; ObjectId.isValid(‘microsoft123’); //true ObjectId.isValid(‘timtomtamted’); //true ObjectId.isValid(‘551137c2f9e1fac808a5f572’); //true What has been working for me is casting a string to an objectId and then … Read more

onkeyup and onfocusout is not working in jQuery Validate

You would never use the .valid() method within the .validate() method. Refer to the source code of onkeyup and onfocusout to see how it’s done. Use this.element(element) instead of $(element).valid() To over-ride the default functionality (“lazy validation”) of onkeyup and onfocusout and use “eager” validation instead… $(‘#myform’).validate({ onkeyup: function(element) { this.element(element); // <- “eager validation” … Read more

How to pass two anonymous functions as arguments in CoffeScript?

I think the problem lies with using single line comments //. Single-line comments enclosed in /* .. */ seem to work fine. Here’s an equivalent example with something other than a comment. $(‘element’).hover( -> console.log(“first”) -> console.log(“second”) ) Or with comments using /* .. */. $(‘element’).hover( -> /* first */ -> /* second */ ) … Read more