<script type = "text/javascript">
Is there anything wrong with my validateEmail function that is causing it not to work properly?
https://pastebin.com/KQZSHMn9
-
We need to see your function to determine what's going on. Also, more details about "not to work properly". What's a test case that fails? How is it failing?mykaf– mykaf2022-04-22 18:52:30 +00:00Commented Apr 22, 2022 at 18:52
-
pastebin.com/KQZSHMn9 Here it is. It puts up an error message when I don't enter anything in but it doesn't fail when I don't put in "@" or anything else like that.MattyB323– MattyB3232022-04-22 18:55:23 +00:00Commented Apr 22, 2022 at 18:55
-
Please include your code in your post, not as a link or an image. Why is uploading images of code on Stack Overflow such a big "no no"?mykaf– mykaf2022-04-22 18:56:09 +00:00Commented Apr 22, 2022 at 18:56
-
It won't let me include it as code for some reason. I copy and pasted it where it told me to but it wouldn't work. I had to put it in pastebin instead.MattyB323– MattyB3232022-04-22 18:58:26 +00:00Commented Apr 22, 2022 at 18:58
Add a comment
|
1 Answer
Your code isn't complete; I guess this is because you are a new contributor. There is an example for email validator code:
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(inputText.value.match(mailformat))
{
alert("Valid email address!");
document.form1.text1.focus();
return true;
}
else
{
alert("You have entered an invalid email address!");
document.form1.text1.focus();
return false;
}
}
li {list-style-type: none;
font-size: 16pt;
}
.mail {
margin: auto;
padding-top: 10px;
padding-bottom: 10px;
width: 400px;
background :
#D8F1F8;
border: 1px soild
silver;
}
.mail h2 {
margin-left: 38px;
}
input {
font-size: 20pt;
}
input:focus, textarea:focus{
background-color:
lightyellow;
}
input submit {
font-size: 12pt;
}
.rq {
color:
#FF0000;
font-size: 10pt;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript form validation - checking email</title>
<link rel='stylesheet' href='form-style.css' type='text/css' />
</head>
<body onload='document.form1.text1.focus()'>
<div class="mail">
<h2>Input an email and Submit</h2>
<form name="form1" action="#">
<ul>
<li><input type='text' name='text1'/></li>
<li> </li>
<li class="submit"><input type="submit" name="submit" value="Submit" onclick="ValidateEmail(document.form1.text1)"/></li>
<li> </li>
</ul>
</form>
</div>
<script src="email-validation.js"></script>
</body>
</html>
5 Comments
MattyB323
Thank you. But i'm not sure where I went wrong in my code. Would you be able to explain to me please?
MattyB323
imgur.com/a/QtqpgwC I'm not sure what's wrong with my validateEmail function.
MattyB323
pastebin.com/KQZSHMn9 here it is in pastebin.
mstephen19
@MattyB323 Use regex.
MattyB323
does it not work in pastebin?