I'm using validation.js plugin and in the case I want it I was trying to make some changes to it but after a lot of thinking and testing and searching I got nothing , at least nothing I wanted... I have this code:
$("#form").validate({
rules:
{
phone:
{
required: true,
number: true,
minlength: 6
}
},
messages:
{
phone:
{
required: 'This field is required',
number: 'Invalid phone number',
minlength: 'Minimum length: 6'
}
}
});
every thing is okay but I want it to run some different functions in addition to showing massages , for example when the user type sth less than 6 char , show massage AND RUN Function ONE , if the user type sth except nums it shows massage and also RUN Function TWO
sth like this:
$("#form").validate({
rules:
{
phone:
{
required: true,
number: true,
minlength: 6
}
},
messages:
{
phone:
{
required: 'This field is required',
number: 'Invalid phone number' + function TWO,
minlength: 'Minimum length: 6' + function ONE
}
}
});
can anyone help me please?
You can use a callback
function
instead of astring
as the value for a custom message. Just make sure to return the message from that function. That way you can do any operation before outputting the message. The callbackfunction
takes two arguments, first is the value being passed to the rule, and second is the element.Check the -- JSFiddle Example -- here.