Reputation: 424
I want to limit an html input field to an input like
Name 1 & Name 2,
so that the user can only type in two names in the format
e.g. "Steven & Peter" or "Alex & Jennifer".
I tried it with jQuery "maskedinput" and
$('.picName').mask('aaaaaaaa & aaaaaaaa');
but here the user has to input EXACTLY 8 characters per name, but I want it to set to MAX. 8 characters per name. Does anybody know if that's possible with maskedinput?
Upvotes: 1
Views: 10224
Reputation: 3951
It appears that you can define your own regex inputs: from: http://digitalbush.com/2008/12/08/masked-input-plugin-12/
You should now add custom mask definitions by "$.mask.definitions[char]=regex;"
So, with some regex you can do somthing like this: from: http://www.regular-expressions.info/repeat.html
You could use \b[1-9][0-9]{3}\b to match a number between 1000 and 9999. \b[1-9][0-9]{2,4}\b matches a number between 100 and 99999. Notice the use of the word boundaries.
Upvotes: 1
Reputation: 2005
Try this:
$('.picName').mask('aaaaaaaa & aaaa?aaaa');
Everything behind the question mark will be optional.
Source: Last example on the plugin page: http://digitalbush.com/projects/masked-input-plugin/
Upvotes: 0