I have a jquery custom form validation as below;
jQuery(document).ready(function($) {
var container = $('div.container');
var validator = $("#form2").validate({
errorContainer: container,
errorLabelContainer: $(container),
wrapper: 'li',
meta: "validate"
});
$.validator.addMethod(
"mydate",
function(value, element) {
return value.match(/^\d\d?\-\d\d?\-\d\d\d\d$/);
},
"Please enter a date in the format dd-mm-yyyy"
);
});
I am using;
- jquery-1.4.3.min.js, 2. jquery.validate.js, and 3. jquery.metadata.js
This validates my form <form id="form2" method="post" action=""> and my form field
<input id="datepick" name="LDate" class=" {validate:{required:true,mydate : true }}" style="width: 85px">
The empty error messages (required form field messages) are smartly displayed in a separate container as below;
<div class="container2">
<label for="datepick" class="error">Please enter LDate</label>
</div>
, which is initially hidden from user using style
div.container2 {
display: none
}
and will be visible on error.
The script checks the format of data entered in form field using jquery add methord. But my custom error message "Please enter a date in the format dd-mm-yyyy" is displayed next to the form field in a list format. I want to move this error message to the above <div class="container2">. How can I make this possible??
Thanks in advance.. 🙂
blasteralfred
The documentation for “addMethod” states for the optional “message” argument:
Try changing the line:
to:
I suspect this will do the trick, but I’m not 100% sure.