Skip to content

Commit

Permalink
🎨 re-arrange validation script
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Sep 13, 2016
1 parent 349f54b commit b7b0fcc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

Expand Down

0 comments on commit b7b0fcc

Please sign in to comment.