Need help in form validation... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need help in form validation...

how to validate email address in form using javascript only. i tried following condition but didn't work var eMail = "/^[a-z0-9](\.?[a-z0-9_-]){0,}@[a-z0-9-]+\.([a-z]{1,6}\.)?[a-z]{2,6}$/g"; if (document.myForm.email.value == "" ) { document.myForm.email.focus(); document.getElementById("mail").innerHTML = " * Email cannot be empty"; } else if (document.myForm.email.value == !eMail) { document.myForm.email.focus(); document.getElementById("mail").innerHTML = " * Invalid email"; return false; } else { document.getElementById("mail").innerHtmL = ""; }

5th Jun 2017, 7:14 AM
Rajnish Deshmukh
Rajnish Deshmukh - avatar
4 Answers
5th Jun 2017, 7:08 AM
Elias Papachristos
Elias Papachristos - avatar
0
Try to learn how to use "Regular expressions"
5th Jun 2017, 7:08 AM
Loai Hazima
Loai Hazima - avatar
0
You can do it with HTML only <input type="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}
quot; />
5th Jun 2017, 7:45 AM
Calviղ
Calviղ - avatar
0
thanks everyone for help.
5th Jun 2017, 6:34 PM
Rajnish Deshmukh
Rajnish Deshmukh - avatar