Created
August 5, 2014 08:38
-
-
Save raeno/56dcec76eb4d0e5fdd11 to your computer and use it in GitHub Desktop.
Форматирование телефонного номера ( Россия )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We use jquery.inputmask plugin to apply mask for the phone number. | |
// Plugin page: https://github.com/RobinHerbots/jquery.inputmask | |
var maskPhone, setPhoneFormValidation, phoneForm, phoneInput; | |
phoneForm = function() { | |
return $('.js-phone-block > form'); | |
} | |
phoneInput = function() { | |
return $('#phone_input'); | |
} | |
setPhoneFormValidation = function() { | |
return phoneNumbernnput.on('submit', function(e) { | |
var phone; | |
phone = phoneInput().val().replace(/[^\d.]/g, ""); | |
if (!phone) { | |
alert('Empty phone'); | |
e.preventDefault(); | |
return false; | |
} | |
return true; | |
}); | |
}; | |
maskPhone = function() { | |
var mask, phone, phone_field; | |
phone_field = phoneInput(); | |
phone = phone_field.inputmask('unmaskedvalue'); | |
mask = '+7(999)999-99-99'; | |
return phone_field.inputmask('remove').val(phone).inputmask('mask', { | |
'mask': mask | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment