by using custom validator to validate an regular expression with email id how to write a code in OnServerValidate propertie anybody can help me to solve please................
below of my code is:
Client Side Javascript:
function ValidateEmailId(source, args) {
var rdbemailid = document.getElementById("<%=rdb_No.ClientID %>");
var emilid = $("#<%= txtEmail.ClientID %>").val();
if (rdbemailid.checked) {
if (emilid == "") {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
}

Kiresh Gangariya52 reputationPosted Jun 3, 2013, 2:21 AM EDT
if (emailid == null || x == "") {
document.getElementById("LabelValidateEmail").innerHTML = "Email Required";
count++;
}
else {
alphaExp = /^[\w\.=-]+@[\w\.-]+\.[\w]{2,3}$/; //regular expression of a valid email address
if (!x.match(alphaExp)) {
document.getElementById("LabelValidateEmail").innerHTML = "Check the Email format";
count++;
} else {
document.getElementById("LabelValidateEmail").innerHTML = "";
}
manjula d131 reputationPosted Jun 3, 2013, 8:13 PM EDT
but i want to use customvalidator only how to generate OnServerValidate propertie by using regular expression with emailid
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 4, 2013, 11:29 AM EDT
i written below code according to your requirement plz chek this
and below .cs code
using System.Configuration;
public partial class Custom_validator : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ServerValidate(object source, ServerValidateEventArgs args)
{
RegexStringValidator r = new RegexStringValidator(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
try
{
r.Validate(args.Value);
args.IsValid = true;
}
catch (ArgumentException ee)
{
ee.Message.ToString();
args.IsValid = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
}
}
}
plz check this and reply
manjula d131 reputationPosted Jun 5, 2013, 1:59 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 5, 2013, 6:30 AM EDT