|
|
@@ -3597,14 +3597,15 @@
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * Return true if the input value contains a valid US phone number only
|
|
|
+ * Return true if the input value contains a valid phone number for the country
|
|
|
+ * selected in the options
|
|
|
*
|
|
|
* @param {BootstrapValidator} validator Validate plugin instance
|
|
|
* @param {jQuery} $field Field element
|
|
|
* @param {Object} options Consist of key:
|
|
|
* - message: The invalid message
|
|
|
* - country: The ISO 3166 country code
|
|
|
- * Currently it only supports United State (US) country
|
|
|
+ * Currently it only supports United State (US) or United Kingdom (GB) countries
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
validate: function(validator, $field, options) {
|
|
|
@@ -3615,6 +3616,12 @@
|
|
|
|
|
|
var country = (options.country || 'US').toUpperCase();
|
|
|
switch (country) {
|
|
|
+ case 'GB':
|
|
|
+ // Make sure the input looks like a valid UK phone number based on the guide at
|
|
|
+ // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
|
|
|
+ // Test: http://regexr.com/38uhv
|
|
|
+ value = value.trim();
|
|
|
+ return (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
|
|
|
case 'US':
|
|
|
default:
|
|
|
// Make sure US phone numbers have 10 digits
|