RegularExpressionValidator control Example
RegularExpressionValidator control Example
The RegularExpressionValidator control confirms that the entry matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses, telephone numbers, postal codes, and so on. Some common regular expressions are:
US Zip Codes: \d{5}
US Phone Numbers: \d{3}-\d{3}-\d{4}
Email address: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
RegularExpressionValidator uses two key properties to perform its validation: ControlToValidate contains the value to validate, and ValidationExpression contains the regular expression to match.
...........Design code for RegularExpressionvalidator control.......
....................................................................
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Untitled Page
........................................................................................................................................
...........................cs code..................................
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)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("u have entered valid email");
}
}
....................................................................