Reputation: 574
I need to mask a form field to only allow facebook page urls, using jQuery Mask Plugin (http://igorescobar.github.io/jQuery-Mask-Plugin/). The current code I'm using is this:
$('input.facebook').mask('https://facebook.com/R', {translation: {'R': {pattern: /[\S]/},recursive: true}, maxlength: false});
This almost works, but I can only enter a single character after the '...k.com/', when I need to be able to enter any number of characters.
Any idea what I'm doing wrong?
Upvotes: 1
Views: 2020
Reputation: 888
It looks like the recursive option is in the incorrect place, it should be a sibling of the pattern.
$(document).ready(function() {
$('input.facebook').mask('https://facebook.com/ZZ', {
translation: {
'Z': { pattern: /\S/, optional: true, recursive: true}
},
maxlength: false
});
});
We use ZZ instead of just Z in the matcher because recursive is meant to repeat any static characters intrinsic to the mask, so for some reason, if there's only one matching character, it repeats the static character before it.
Upvotes: 3