<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function validate()
{
var email=document.getElementById("txtemailid").value;
var phone=document.getElementById("txtphno").value;
var regexp1=/^([a-zA-Z0-9]+[\_\-\.]?)+@([a-zA-Z0-9]+\.)+[a-zA-Z0-9]+$/;
var regexp2=/^[0-9]+$/;
var Restr = /^[a-z]([\.\_]?[a-z\d]+)*\@[a-z\d]+([\.\_\-][a-z\d]+)+$/;
if (!regexp1.test(email))
{
alert("Please Enter Valid E-mail Adress");
return false;
}
else
{
alert("Valid Email address");
return true;
}
if(!regexp2.test(phone))
{
alert("phone number must contain only numbers");
return false;
}
if(phone.length!=10)
{
alert("Phone number length should be 10");
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2 style=" color:blue; font-style:normal ">
Email Javascript Validation
<br /> in asp.net
</h2>
<div style="text-align:center">
<table>
<tr>
<td><asp:Label ID="lblemailid" runat="server" Text="Email ID"></asp:Label></td>
<td><asp:TextBox ID="txtemailid" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="lblphno" runat="server" Text="Phone Number"></asp:Label></td>
<td><asp:TextBox ID="txtphno" runat="server"></asp:TextBox></td>
</tr>
</table>
</div>
<div style="text-align:center; margin-right:78%;">
<asp:Button ID="btnsubmit" Text="Submit" runat="server"/>
</div>
</form>
</body>
</html>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnsubmit.Attributes.Add("onclick", "return validate();");
}
}
No comments:
Post a Comment