Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to combine to phone masks? #713

Open
lumenier1 opened this issue Jun 13, 2019 · 1 comment
Open

How to combine to phone masks? #713

lumenier1 opened this issue Jun 13, 2019 · 1 comment

Comments

@lumenier1
Copy link

I want to pas phone numbers with different formats: '+{7}(000)000-00-00' and '8(000)000-00-00'
How to do it with this mask?

@pyetrosafe
Copy link

pyetrosafe commented Jun 13, 2019

Hi... Your question can be resolved by the code below (using the last version jQueryMask v1.11.1):

<div class="col-xs-6 col-sm-6 col-md-4">
  <div class="form-group">
    <label>Combined Values</label>
    <input type="text" name="combined" class="form-control">
  </div>
</div>

// Mask Phones
var combinedPhonesBehavior = function (val) {
			return val.charAt(0) == '+' ? '+{0}(000)000-00-00' : '+0(000)000-00-00';
		},
    combinedPhonesOptions = {
    	onKeyPress: function(val, e, field, options) {
      	field.mask(combinedPhonesBehavior.apply({}, arguments), options);
      },
      translation: { '+': { pattern: /[+]/, optional: true} }
    };

$(function() {
	$(':input[name=combinedPhones]').mask(combinedPhonesBehavior, combinedPhonesOptions);
});

See in action here: https://jsfiddle.net/pyetrosafe/ug18qj9m/5/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants