First of all you can use the HTML5 form validation API. But this requires, that the browser supports this API or you are using a polyfill. Currently FF4+, IE10+, Chrome and Safari do support the API. But FF does not fully support the number type.
If you want to use the HTML5-API:
use the input event instead of the keyup event. This is much better event for your task (think, paste, cut and so on).
Simply use the :valid Selector to test, wether input is valid (if not polyfilled, will throw an error in IE9-)
I have put together a simple solution for you, which is using webshims to polyfill the API for you.
But to be honest, I question your approach. You can simply use a form with a button, proper action attribute and a month named type="number" instead of a link + JS for your solution and do not need to add JS at all. Code could look like this and you get the HTML form validation for free:
<form action="#">
<div>
<button class="text" type="submit">to month: </button>
<input type="number" name="month" placeholder="Month" min="1" max="12" required value="1" size="2" />
</div>
</form>
My example also shows how to style a button as a link.