This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes why my email validation is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "why my email validation is not working " Watch "why my email validation is not working " New topic
Author

why my email validation is not working

raj talatam
Ranch Hand

Joined: Apr 19, 2012
Posts: 87
please change the code to validate email



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="javascript">
function validate(){
var name=document.form.name.value;
var city=document.form.city.value;
var category=document.form.category.value;
var email=document.form.email.value;
var phone=document.form.phone.value;
var mobile=document.form.mobile.value;
var fax=document.form.fax.value;
var state=document.form.state.value;
var contactperson=document.form.contactperson.value;
var website=document.form.website.value;
var govcernumber=document.form.govcernumber.value;
var estayear=document.form.estayear.value;
var ranking=document.form.ranking.value;
var timings=document.form.timings.value;
var address=document.form.address.value;
var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;


if(name==""){
alert("Enter Username!");
return false;
}
if(city==""){
alert("Enter city!");
return false;
}
if(category==""){
alert("Enter category!");
return false;
}
if (pattern.test(email)) {
alert("Please enter a valid email Id");
return false;

}
if(phone==""){
alert("Enter phone!");
return false;
}
if(mobile==""){
alert("Enter mobile!");
return false;
}
if(fax==""){
alert("Enter fax!");
return false;
}
if(state==""){
alert("Enter state!");
return false;
}
if(contactperson==""){
alert("Enter contactperson!");
return false;
}
if(website==""){
alert("Enter website!");
return false;
}
if(govcernumber==""){
alert("Enter govcernumber!");
return false;
}

if(estayear==""){
alert("Enter estayear!");
return false;
}
if(ranking==""){
alert("Enter ranking!");
return false;
}
if(timings==""){
alert("Enter timings!");
return false;
}

if(address==""){
alert("Enter address!");
return false;
}

return true;
}


</script>
<form name="form" method="post" action="/companydeatails/store.jsp" onsubmit="javascript:return validate();onClick=
checkEmail(document.form.email.value);">
<table>
<tr><td>name:</td><td><input type="text" name="name"></td></tr>
<tr><td>city:</td><td><input type="text" name="city"></td></tr>
<tr><td>category:</td><td><input type="text" name="category"></td></tr>
<tr><td>email:</td><td><input type="text" name="email"></td></tr>

<tr><td>phone:</td><td><input type="text" name="phone"></td></tr>
<tr><td>mobile :</td><td><input type="text" name="mobile"></td></tr>
<tr><td>fax:</td><td><input type="text" name="fax"></td></tr>
<tr><td>state:</td><td><input type="text" name="state"></td></tr>
<tr><td>contactperson:</td><td><input type="text" name="contactperson"></td></tr>
<tr><td>website:</td><td><input type="text" name="website"></td></tr>
<tr><td>govcernumber:</td><td><input type="text" name="govcernumber"></td></tr>
<tr><td>estayear:</td><td><input type="text" name="estayear"></td></tr>
<tr><td>ranking:</td><td><input type="text" name="ranking"></td></tr>
<tr><td>timings:</td><td><input type="text" name="timings"></td></tr>
<tr><td>address:</td><td><input type="text" name="address"></td></tr>

<tr><td></td><td><input type="submit" value="Login"></td></tr>
<tr><td></td><td><a href="form.jsp">Register Here</a></td></tr>
</table>
</form>
</html>
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

rajendar talatam wrote:please change the code to validate email


Rajendar, when you ask for help in forums which are volunteer driven, you are expected to ShowSomeEffort in asking your question. Your post doesn't even explain the issue you are running into. Dumping random HTML or other code and asking others to change it to get it working isn't the right way to ask for help. If you really do need help, please take some time to add more details about the issue you are running into and form a proper question. Also while posting code, logs, xml content or other similar content, please use the code blocks to wrap that text (you can use the Code button in the message editor window and also the Preview button to see it's properly formatted).

[My Blog] [JavaRanch Journal]
 
jQuery in Action, 2nd edition
 
subject: why my email validation is not working