i am using jQuery Interrnational Telephone Input Plugin for getting countrycode along with the phone number. html code
<div class="form-group">
<input type="tel" placeholder="Phone*" id="telephone" name="telephone" class="form-control">
</div>
initialistion of plugin
jQuery("#telephone").intlTelInput({
// options here
allowDropdown:true,
autoHideDialCode:true,
autoPlaceholder:"polite",
separateDialCode:true,
customPlaceholder:null
});
how to grt the full country code with the phone number.
I was not able to recreate the plugin using jQuery. But see an example below with vanilla JS. The plugin has a public method getNumber()
through which you can get the number.
var input = document.querySelector("#telephone"); let iti = window.intlTelInput(input, { // options here allowDropdown: true, autoHideDialCode: true, autoPlaceholder: "polite", separateDialCode: true, customPlaceholder: null, utilsScript: "https://raw.githack.com/jackocnr/intl-tel-input/master/build/js/utils.js" }); $(".get-number").on("click", function() { console.log(iti.getNumber()); });
.get-number { padding: 0.5em 1em; background-color: lightblue; border-radius: 0.2em; display: inline-block; margin: 1em 0; cursor: pointer; }
<script src="https://raw.githack.com/jackocnr/intl-tel-input/41735773e78c39aad6aaee53a6126215f64aeb57/build/js/intlTelInput.js"></script> <link href="https://raw.githack.com/jackocnr/intl-tel-input/master/build/css/intlTelInput.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="form-group"> <input type="tel" placeholder="Phone*" id="telephone" name="telephone" class="form-control"> </div> <div class='get-number'> Get Number </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.