You will have better luck using this sort of foam if you apply it to the door rather than the molding... so that it compresses rather than scraping across something or having something scrape across it.... won't work well that way.  If you put it ON the door, on the side that you want sealed (not on the edge of the door, not on the door fame, but right ON the door) it will look terrible but will seal and stay in place.  Put thick foam like this one where you feel the most air coming through, and trim it or put thinner foam on the hinge part of the molding, so that the backside of the door presses up against it.  Putting it on the edges of the door, especially UNDER the door will not work more than a couple of times.  Adjust the thickness with a box knife or scissors so that the door can still close, but not pop back open without you noticing.  The cheap hollow-core doors tend to warp in weather changes, so it's good to buy plenty if you have doors you need to have sealed.