Jquery Validator and Mask Plugin
I used the Input Mask Jquery plugin to mask the credit card field. My disguised code looks like this:
$(".cardField").mask("9999 9999 9999 9999");
The problem is that I also used the validator plugin with the following condition:
rules: {
cardField: {
required: true,
digits: true,
minlength: 16,
maxlength: 16
}
}
Now when I type something it always results in an error due to spaces. How can I solve this?
Also, before I post it back with $ post, I want to return it as a number with no spaces. I used the unmasked () method but returns an object instead.
var creditCardValue = $(".cardField").unmask().mask("9999 9999 9999 9999");
$(".cardField").val(creditCardValue);
so how can i do it right?
Thank.
source to share
I checked out the plugin I believe you are using - the JQuery Mask Plugin . But as far as I can see the method unmask
just removes the forced formatting and the value of the textbox is retained as such. For example -
Date - 12/12/2012 - with mask
Date - 12/12/2012 - after disclosure
So, you're stuck with having to remove the extra formatting yourself. You might consider adding a custom check for that particular field and then revert to the format of your wish on the server or before you put it on your server. I think this is the only solution available to you right now.
source to share