Skip to content

Instantly share code, notes, and snippets.

@vordan
Last active April 30, 2021 16:30
Show Gist options
  • Save vordan/ee7d5abbe86a50e51631fa0fda5fa2fa to your computer and use it in GitHub Desktop.
Save vordan/ee7d5abbe86a50e51631fa0fda5fa2fa to your computer and use it in GitHub Desktop.
RegEx za makedonski telefonski broevi
$.fn.validMKPhone = function() {
// https://regex101.com/r/GelZQf/1
let $input = $(this);
let mk_phone_regexp = new RegExp(/[0][237][0-9]{0,1}[\-\ ]\d{3,4}[\-\ ]\d{3}/);
return mk_phone_regexp.test($input.val());
}
@vordan
Copy link
Author

vordan commented Apr 30, 2021

$('#'+pub.idp+'telefon').keyup(function(e) {
  if (e.keyCode == 9 || e.keyCode == 13) {
    _check_phone_is_valid();
    $('#'+pub.idp+'language_id').focus();
  }
  else {
      setTimeout(jQuery.proxy(function() {
	      $(this).val($(this).val().replace(/[^0-9\ \-]/g, ''));
	      _check_phone_is_valid();
      }, $(this)), 0);
  }
});

function _check_phone_is_valid() {
  let _value = nz($('#'+pub.idp+'telefon').val());
  
  let _is_valid = $('#'+pub.idp+'telefon').validMKPhone();
  
  if (_is_valid) {
    $('#'+pub.idp+'telefon_check').removeClass('fa-check-circle fa-exclamation-circle red-icon green-icon').addClass('fa-check-circle green-icon');
  }
  else {
    $('#'+pub.idp+'telefon_check').removeClass('fa-check-circle fa-exclamation-circle red-icon green-icon').addClass('fa-exclamation-circle red-icon');
  }
}

<div class="form-group">
<label class="condensed" for="telefon">Телефон <i class="fa fa-asterisk red"></i></label>
<div class="input-group">
  <input type="text" id="telefon" class="form-control kandidat-edit focus" tabindex="10210" placeholder="07x 123 456">
  <div class="input-group-addon pointer"><i id="{idp}telefon_check" class="fa fa-exclamation-circle red-icon"></i></div>
</div>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment