phoneMask jQuery

phoneMask jQuery

by kirito0709

HTML

<div class="form-row">
        <label for="phone">Ваш телефон<span class="required">*</span></label>
        <input type="text" name="phone" id="phone" maxlength="25" autocomplete="on" required/>
    </div>

JavaScript

(function($) {
  $.fn.kk_mask = function() {
    var a, t;
    a = this;
    this.keyup(function() {
      t = $(a).val();
      t = t.replace(/[^+\d]/g, '');
      t = t.replace(/^([^\+]*\+)|\+/g, '$1');
      $(a).val(t);
    });
		this.bind('paste', function() {
			t = $(a).val();
      t = t.replace(/[^+\d]/g, '');
      t = t.replace(/^([^\+]*\+)|\+/g, '$1');
      $(a).val(t);
		});
  };
})(jQuery);

$(function() {
  $("#phone").kk_mask();
});