I have been trying since to build a custom validator using Valdr AngularJs plugin with no success.
What I want to archive is an input text that should receive date and time format like : dd/MM/yyyy hh:mm (12/04/2015 12:32:10)
Based on Valdr documentation, this is what I have done so far :
myApp.factory('customValidator', function () {
return {
name: 'customValidator', // this is the validator name that can be referenced from the constraints JSON
validate: function (value, arguments) {
// value: the value to validate
// arguments: the validator arguments
return value === arguments.onlyValidValue;
}
};
});
myApp.config(function(valdrProvider)
{
valdrProvider.addValidator('customValidator');
valdrProvider.addConstraints(
{
'Person':
{
'date_send':
{
'customValidator':
{
'onlyValidValue':'^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[2][0]\d{2})$|^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[2][0]\d{2}\s([0-1]\d|[2][0-3])\:[0-5]\d\:[0-5]\d)$',
'message': 'Please date and time format has to be : 12/04/2015 12:32:10'
}
}
}
});
});
Then in my form, I have the following :
<input class="input" name="date_send" id="date_send" type="text" ng-model="date_send" />
But it doesn't work.
I will appreciate any help.
Thank you !