Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. /**
  2. *
  3. * Comprobar si una cadena es un número hexadecimal usando
  4. * expresiones regulares
  5. * @author parzibyte
  6. * Visita: parzibyte.me
  7. */
  8.  
  9. const esHexadecimal = numeroHexadecimal => /^[0-9A-F]+$/ig.test(numeroHexadecimal);
  10.  
  11. const cadenasParaProbar = [
  12. "asd",
  13. "AAA",
  14. "fff",
  15. "affffabbc",
  16. "abcdef",
  17. "000000",
  18. "a",
  19. "parzibyte",
  20. "z",
  21. "001090",
  22. "qwe",
  23. "",
  24. ];
  25.  
  26. cadenasParaProbar.forEach(cadena => {
  27. console.log("Probando %s. ¿Es hexadecimal? %s", cadena, esHexadecimal(cadena));
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement