@Aimal-125
Posted
Use this js code for validation:-
let regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
function myfunc() {
if(x.value == "") {
y.style.visibility = "visible";
y.innerHTML = "Empty Field";
y.style.color = "hsl(0, 74%, 74%)";
q.style.border = "2px solid hsl(0, 74%, 74%)";
a.style.visibility = "visible";
}
else if(!(x.value.match(regex))) {
y.style.visibility = "visible";
y.innerHTML = "Please provide a valid email";
y.style.color = "hsl(0, 74%, 74%)";
q.style.border = "2px solid hsl(0, 74%, 74%)";
a.style.visibility = "visible";
}
else if(x.value.match(regex)) {
y.style.visibility = "visible";
y.innerHTML = "Valid email";
y.style.color = "green";
q.style.border = "1px solid hsl(0, 6%, 24%)";
a.style.visibility = "hidden";
}
}
z.addEventListener("click", myfunc);
where z is the pink button. y is the red error image. q is the div in which input element is. x is input type text. a is the p element in which error msg will display.
Marked as helpful
@suruaino
Posted
wow, that a whole lot of information. Thanks, I really appreciate.@Aimal-125