diff --git a/lib/validation.js b/lib/validation.js index bea2db7..13269c9 100644 --- a/lib/validation.js +++ b/lib/validation.js @@ -21,13 +21,15 @@ const isMobilePhone = require('validator/lib/isMobilePhone'); module.exports = function telephoneValidation(input, settings) { - const set = settings; + // disable eslint for var because this is a browser-bound script + var locale = 'en-US'; // eslint-disable-line no-var - if (!set.hasOwnProperty('target') || !set.target.hasOwnProperty('locale') || set.target.locale === '') { - set.target.locale = 'en-US'; + // check settings for locale + if (settings.hasOwnProperty('target') && settings.target.hasOwnProperty('locale') && settings.target.locale !== '' && typeof settings.target.locale === 'string') { + locale = settings.target.locale; } - if (input.target.value && !isMobilePhone(input.target.value, set.target.locale)) { + if (input.target.value && !isMobilePhone(input.target.value, locale)) { return `${input.target.name} must be a phone number`; }