min(max(i.value, 1), max_pages)? You can use Math.max, or else underscore (and I wouldn't be surprised if we had other versions of it loaded on the page)