Last active
December 15, 2022 11:35
-
-
Save danielfreitasce/b3340236be71ed8831d645a596d6d538 to your computer and use it in GitHub Desktop.
Some validations
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
function isEmptyParam(param) { | |
if (param || param.length > 0) | |
return false; | |
else | |
return true; | |
} | |
function verifyMinCaracteres(min, str) { | |
if (str.length >= min) | |
return true; | |
else | |
return false; | |
} | |
function verifyMaxCaracteres(max, str) { | |
if (str.length === max) | |
return true; | |
else | |
return false; | |
} | |
function isInteger(num) { | |
if (Number.isInteger(num)) | |
return true; | |
else | |
return false; | |
} | |
function isRealNumber(num) { | |
if (!Number.isInteger(num) && isReal(num)) | |
return true; | |
else | |
return false; | |
} | |
function isReal(num) { | |
return typeof num == 'number' && !isNaN(num); | |
} | |
console.log(`100 is real number : ${isReal(100)}`); | |
console.log(`100.2334532322333 is real number: ${isRealNumber(100.2334532322333)}`); | |
console.log(`100 is intenger: ${isInteger(100)}`); | |
console.log(`100.122345 is intenger: ${isInteger(100.122345)}`); | |
console.log(`'Olá mundo!' has 10 characters: ${verifyMaxCaracteres(10, 'Olá mundo!')}`); | |
console.log(`'Hello' has at least 3 characters: ${verifyMinCaracteres(3, 'Hello')}`); | |
console.log(`'Oi' has at least 3 characters: ${verifyMinCaracteres(3, 'Oi')}`); | |
console.log(`'' is a empty string: ${isEmptyParam('')}`); | |
console.log(`'Olá mundo!' is a empty string: ${isEmptyParam('Olá mundo!')}`); | |
console.log(`100 is a empty param: ${isEmptyParam(100)}`); | |
console.log(`null is a empty param: ${isEmptyParam(null)}`); | |
console.log(`undefined is a empty param: ${isEmptyParam()}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment