+ 2
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 data@data.co it should show alert message or pop up message any other emails is accepted.
11 Antworten
+ 5
Eric 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
+ 3
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.
+ 2
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">
+ 1
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);
+ 1
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?
+ 1
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);
}
+ 1
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.
+ 1
Also add else for first if condition to verify that email is correct
+ 1
Thanks guys for Your help. I really appreciate it. You really helped me.
0
Give me please HTML code
0
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