Javascript validation
simple javascript validation with jQuery
HTML
<label for="day">Day<input type="text" id="day" name="day"/></label><br />
<label for="month">Month<input type="text" id="month" name="month" maxlength=2/></label>
<input type="submit" onclick="validate()" value="test"/>
<pre id="original"></pre>
<pre id="trimmed"></pre>
JavaScript
function validate(){
alert("hi");
return false;
}
var str = " lots of spaces before and after ";
$("#original").html("Original String: '" + str + "'");
$("#trimmed").html("$.trim()'ed: '" + $.trim(str) + "'");
$('#day').live('keydown', function(e){
keyCode = e.keyCode || e.which;
if(keyCode == 9){
if($(this).val()<1 || $(this).val()>32){
e.preventDefault();
$(this).trigger('select');
console.log('error');
}
}
});
$('#month').live('keydown', function(e){
keyCode = e.keyCode || e.which;
if(keyCode == 9){
if($(this).val()<1 || $(this).val()>12){
e.preventDefault();
$(this).trigger('select');
console.log('error');
}
}
});