// Import readline untuk mengambil input dari pengguna
const readline = require('readline');
// Membuat interface untuk input/output
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Regex untuk validasi email
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
// Fungsi untuk memvalidasi email
function validateEmail(email) {
return emailRegex.test(email);
}
// Meminta input email dari pengguna
rl.question('Masukkan alamat email: ', (email) => {
if (validateEmail(email)) {
console.log('Email valid');
} else {
console.log('Email tidak valid');
}
rl.close(); // Tutup interface readline setelah selesai
});
Ly8gSW1wb3J0IHJlYWRsaW5lIHVudHVrIG1lbmdhbWJpbCBpbnB1dCBkYXJpIHBlbmdndW5hCmNvbnN0IHJlYWRsaW5lID0gcmVxdWlyZSgncmVhZGxpbmUnKTsKCi8vIE1lbWJ1YXQgaW50ZXJmYWNlIHVudHVrIGlucHV0L291dHB1dApjb25zdCBybCA9IHJlYWRsaW5lLmNyZWF0ZUludGVyZmFjZSh7CiAgICBpbnB1dDogcHJvY2Vzcy5zdGRpbiwKICAgIG91dHB1dDogcHJvY2Vzcy5zdGRvdXQKfSk7CgovLyBSZWdleCB1bnR1ayB2YWxpZGFzaSBlbWFpbApjb25zdCBlbWFpbFJlZ2V4ID0gL15bYS16QS1aMC05Ll8lKy1dK0BbYS16QS1aMC05Li1dK1wuW2EtekEtWl17Mix9JC87CgovLyBGdW5nc2kgdW50dWsgbWVtdmFsaWRhc2kgZW1haWwKZnVuY3Rpb24gdmFsaWRhdGVFbWFpbChlbWFpbCkgewogICAgcmV0dXJuIGVtYWlsUmVnZXgudGVzdChlbWFpbCk7Cn0KCi8vIE1lbWludGEgaW5wdXQgZW1haWwgZGFyaSBwZW5nZ3VuYQpybC5xdWVzdGlvbignTWFzdWtrYW4gYWxhbWF0IGVtYWlsOiAnLCAoZW1haWwpID0+IHsKICAgIGlmICh2YWxpZGF0ZUVtYWlsKGVtYWlsKSkgewogICAgICAgIGNvbnNvbGUubG9nKCdFbWFpbCB2YWxpZCcpOwogICAgfSBlbHNlIHsKICAgICAgICBjb25zb2xlLmxvZygnRW1haWwgdGlkYWsgdmFsaWQnKTsKICAgIH0KICAgIHJsLmNsb3NlKCk7IC8vIFR1dHVwIGludGVyZmFjZSByZWFkbGluZSBzZXRlbGFoIHNlbGVzYWkKfSk7Cg==