Created
November 23, 2019 18:58
-
-
Save myogeshchavan97/44e523c5b3bfb2350e9b528ba88c1977 to your computer and use it in GitHub Desktop.
Field Validation Using ES6 Syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isNotEmpty = fieldName => fieldValue => fieldValue.trim().length > 0 || fieldName[0].toUpperCase() + fieldName.slice(1) + ' is required.'; | |
const fieldName = isNotEmpty('name'); | |
let isValid = fieldName('David'); | |
console.log(isValid); // true | |
isValid = fieldName(''); | |
console.log(isValid); // Name is required |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment