在这里我验证所选日期大于今天的日期。您可以根据需要进行更改。
<script>
AUI().ready('aui-form-validator', 'aui-overlay-context-panel', function(A) {
A.mix(
YUI.AUI.defaults.FormValidator.RULES,
{
dateCustomRule: function(val, fieldNode, ruleValue) {
var val = new Date(Date.parse(val,"MMM dd yyyy"));
var today=new Date();
return (val>today);
}
},
true
);
var validator2 = new A.FormValidator({
boundingBox: document.<portlet:namespace/>form,
fieldContainer: 'p',
rules: {
<portlet:namespace />dueDate:{
required: true,
dateCustomRule:true
}
},
fieldStrings: {
<portlet:namespace />dueDate: {
required: 'Due Date Required',
dateCustomRule: 'Date must be greater than Today\'s Date'
}
},
on: {
validateField: function(event) {
},
validField: function(event) {
},
errorField: function(event) {
},
submitError: function(event) {
var formEvent = event.validator.formEvent;
var errors = event.validator.errors;
},
submit: function(event) {
var formEvent = event.validator.formEvent;
return false;
}
}
});
});
</script>