Created
October 3, 2019 17:00
-
-
Save parzibyte/09925c54400273f9ebcdc87ffa751da8 to your computer and use it in GitHub Desktop.
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
/** | |
* Saber si carácter es dígito con JavaScript | |
* | |
* https://parzibyte.me/blog | |
* | |
*/ | |
const esDigito = (caracter) => { | |
let ascii = caracter.charCodeAt(0); | |
return ascii > 47 && ascii < 58; | |
} | |
// Probar | |
const caracteres = ["A","B","0","4","_","9", " "]; | |
caracteres.forEach(caracter => { | |
console.log("¿'%s' es dígito? %s", caracter, esDigito(caracter)); | |
}); | |
/* | |
Salida: | |
¿'A' es dígito? false | |
¿'B' es dígito? false | |
¿'0' es dígito? true | |
¿'4' es dígito? true | |
¿'_' es dígito? false | |
¿'9' es dígito? true | |
¿' ' es dígito? false | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment