email restriction using javascript
So basically i would like to know a function how to restrict email validation if provided email is ending with .co in javascript. for example-if i input [email protected] it should show alert message or pop up message any other emails is accepted.
7/8/2021 10:39:32 AM
Eric Kazhus
11 Answers
New AnswerEric Kazhus I corrected your HTML code as I already here mentioned and changed the function for validation. The result is as follows: https://code.sololearn.com/WQ6DeAXZFY71/?ref=app
Eric Kazhus more better will be if you save you attempt in SL Playground and test it if it works. Then with your question you can provide the link to your code. After will more easier to help you. By the way, you can use HTML5 for the first check of an email. And the second with your function.
line 16 html replace that with <body onLoad='document.testForm.email.focus()'></body> Target form element by name value. If you have ecent of submit on form you must have to submit it, and for that you should add a submit button put this in line 28 to add submit button <input type="submit" value="submit">
Write a function on input type mail. On change With satememt var mail = document.querySelector(".mail").value ; //get input value var check = /.co$/.test(mail); console.log(check);
HTML <form method="POST" name="testForm" action="thanks.html" onsubmit="return validateForm();"> <input id="myInput" type="text" name="email" placeholder="Type your email address here…" > Javascript var email = document.querySelector(".mail").value ; //get input value var check = /.co$/.test(email); console.log(check); am I missing something?
Yes in input tag its id so get element value by id HTML <form method="POST" name="testForm" action="thanks.html" onsubmit="return validateForm();"> <input id="myInput" type="text" name="email" placeholder="Type your email address here…" > Javascript document.querySelector("#myinput").onchange = ()=>{ var mail = document.querySelector("#myinput").value ; var check = /.co$/.test(email); console.log(check); }
Thanks guys for Your answers, I tried all that You suggested but i dont know what I am doing wrong because nothing worked and I tried in different ways. so code is something like that- https://code.sololearn.com/W89A6a16A14a in javascript i have 2 options already and need third one which have to restrict adding email which is ending with .co.
Tun Tun, You can see it here. I corrected your HTML code as I already here mentioned and changed the function for validation. The result is as follows: https://code.sololearn.com/WQ6DeAXZFY71/?ref=app