diff --git a/client/src/lib-app/validations/length-validator.js b/client/src/lib-app/validations/length-validator.js index 3b120e07..f8e2a45a 100644 --- a/client/src/lib-app/validations/length-validator.js +++ b/client/src/lib-app/validations/length-validator.js @@ -1,4 +1,5 @@ import Validator from 'lib-app/validations/validator'; +import _ from 'lodash'; class LengthValidator extends Validator { constructor(length, errorKey = 'INVALID_VALUE', validator = null) { @@ -12,8 +13,10 @@ class LengthValidator extends Validator { let div = document.createElement("div"); div.innerHTML = value; let text = div.textContent || div.innerText || ""; - - if (text.length < this.minlength) return this.getError(this.errorKey); + if(_.every(text, c => c === " ")) { + text = text.replace(/\s/g, ''); + } + if(text.length < this.minlength) return this.getError(this.errorKey); } } diff --git a/client/src/lib-app/validations/space-validator.js b/client/src/lib-app/validations/space-validator.js new file mode 100644 index 00000000..447de4f3 --- /dev/null +++ b/client/src/lib-app/validations/space-validator.js @@ -0,0 +1,19 @@ +import Validator from 'lib-app/validations/validator'; + +class SpaceValidator extends Validator { + constructor(errorKey = 'INVALID_VALUE', validator = null) { + super(validator); + + this.errorKey = errorKey; + } + + validate(value = '', form = {}) { + let div = document.createElement("div"); + div.innerHTML = value; + let text = div.textContent || div.innerText || ""; + + if (text.replace(/\s/g, '').length < 1) return this.getError(this.errorKey); + } +} + +export default SpaceValidator; diff --git a/client/src/lib-app/validations/validator-factory.js b/client/src/lib-app/validations/validator-factory.js index c84278f6..f969cdf7 100644 --- a/client/src/lib-app/validations/validator-factory.js +++ b/client/src/lib-app/validations/validator-factory.js @@ -4,6 +4,7 @@ import RepeatPasswordValidator from 'lib-app/validations/repeat-password-validat import LengthValidator from 'lib-app/validations/length-validator'; import ListValidator from 'lib-app/validations/list-validator'; import ImageSizeValidator from 'lib-app/validations/image-size-validator'; +import SpaceValidator from './space-validator'; let validators = { 'DEFAULT': new Validator(),