-
Notifications
You must be signed in to change notification settings - Fork 0
/
validaciones.js
83 lines (71 loc) · 2.37 KB
/
validaciones.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const textarea = document.getElementById("textoEncriptar");
textarea.addEventListener("input", function () {
const textoIngresado = textarea.value;
// Verificar si hay mayúsculas
if (/[A-Z]/.test(textoIngresado)) {
alert("¡Solo se permiten minúsculas!");
textarea.value = textoIngresado.toLowerCase(); // Convertir a minúsculas
}
// Verificar caracteres especiales
if (/[^a-zA-Z\s]/.test(textoIngresado)) {
alert("¡No se permiten caracteres especiales!");
textarea.value = textoIngresado.replace(/[^a-zA-Z\s]/g, ""); // Eliminar caracteres especiales
}
});
function encriptarTexto() {
var mensaje = document.getElementById("textoEncriptar").value;
console.log(mensaje);
if (mensaje === "") {
// Mostrar mensaje de error y la imagen
document.querySelector(".mensaje-resultado").textContent =
"Ningún mensaje fue encontrado";
} else {
var mensajeNuevo = "";
for (var i = 0; i < mensaje.length; i++) {
switch (mensaje[i]) {
case "a":
mensajeNuevo += "ai";
break;
case "e":
mensajeNuevo += "enter";
break;
case "i":
mensajeNuevo += "imes";
break;
case "o":
mensajeNuevo += "ober";
break;
case "u":
mensajeNuevo += "ufat";
break;
default:
mensajeNuevo += mensaje[i];
}
}
// Ocultar mensaje de error y la imagen
document.getElementById("imgCifrar").style.display = "none";
document.querySelector(".mensaje-resultado").textContent = mensajeNuevo;
}
}
function desencryptarTexto() {
var mensaje = document.getElementById("textoEncriptar").value;
if (mensaje === "") {
// Mostrar mensaje de error y la imagen
document.querySelector(".mensaje-resultado").textContent =
"Ningún mensaje fue encontrado";
} else {
var mensajeNuevo = mensaje
.replace(/ai/g, "a")
.replace(/enter/g, "e")
.replace(/imes/g, "i")
.replace(/ober/g, "o")
.replace(/ufat/g, "u");
// Ocultar mensaje de error y la imagen
document.getElementById("imgCifrar").style.display = "none";
document.querySelector(".mensaje-resultado").textContent = mensajeNuevo;
}
}
function copyTexto() {
var textoCopiar = document.querySelector(".mensaje-resultado").textContent;
document.getElementById("textoEncriptar").value = textoCopiar;
}