I'm needing to write my own javascript rules to validate a form.
I have a field named code
and I need a special validation to it:
This field have exactly 13 positions. The first and second are letters and the last and penultimate one are letters too. The other positions (3-11) are numbers.
So, how can I validate this field with these conditions?
<html>
<head>
<script type="text/javascript"
src="javascript/jquery-1.8.2.min.js" >
</script>
<script type="text/javascript"
src="javascript/jquery.validate.min.js" >
</script>
</head>
<body>
<form id="meu_form" action="" method="post" >
Code:<br />
<input type="text" name="code" id="code" /><br />
<input type="submit" value="Save" />
</form>
</body>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#meu_form').validate({
rules:{
code:{
required: true,
minlength: 13
maxlength: 13
}
},
messages:{
code:{
required: "Required field.",
minlength: "Exactly 13 length."
}
}
});
});
</script>
</html>