Skip to content

Commit

Permalink
added validationScript option
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Feb 24, 2014
1 parent 5ee159d commit 0650761
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 42 deletions.
29 changes: 24 additions & 5 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ author: Jack O'Connor (http://jackocnr.com)

var pluginName = "intlTelInput", id = 1, // give each instance it's own id for namespaced event handling
defaults = {
// united states and united kingdom
preferredCountries: [ "us", "gb" ],
// don't display the +1 prefix when America is selected
americaMode: false,
onlyCountries: [],
defaultStyling: "inside",
// if there is just a dial code in the input: remove it on blur, and re-add it on focus
autoHideDialCode: true,
// default country
defaultCountry: "",
// character to appear between dial code and phone number
dialCodeDelimiter: " "
dialCodeDelimiter: " ",
// position the selected flag inside or outside of the input
defaultStyling: "inside",
// display only these countries
onlyCountries: [],
// the countries at the top of the list. defaults to united states and united kingdom
preferredCountries: [ "us", "gb" ],
// specify the path to the libphonenumber script to enable validation
validationScript: ""
}, keys = {
UP: 38,
DOWN: 40,
Expand Down Expand Up @@ -190,6 +197,12 @@ Plugin.prototype = {
that._showDropdown();
}
});
if (this.options.validationScript) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = this.options.validationScript;
document.body.appendChild(script);
}
},
// on focus: if empty add dial code. on blur: if just dial code, then empty it
_initAutoHideDialCode: function() {
Expand Down Expand Up @@ -525,6 +538,12 @@ Plugin.prototype = {
// the first is "flag" and the second is the 2-char country code
var countryCode = this.selectedFlagInner.attr("class").split(" ")[1];
return this._getCountryData(countryCode);
},
// validate the input val - assumes the global function isValidNumber
isValidNumber: function() {
var val = $.trim(this.telInput.val());
var countryData = this.getSelectedCountryData();
return window.isValidNumber(val, countryData.iso2);
}
};

Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 0650761

Please sign in to comment.