Regular Expressions are stored in System.Text.RegularExpressions namespace.
There is useful Regex class.
I Recommend you to use regex pattern [^ ]...@[^ ]+\.[^ ]+. This is the easiest
for the e-mail you can find...
The example code is:
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Regex regex = new Regex(@"[^ ]...@[^ ]+\.[^ ]+");
MatchCollection matches = regex.Matches("[email protected] then
some pause, [email protected] and nothing more");
foreach (Match match in matches)
Console.WriteLine(match.Value);
Console.ReadKey();
}
}
}
2009/8/11 Maddy <[email protected]>
> The Below snippet is my code for TextBox Float validation(its working fine)
>
>
> public class textboxFloat : System.Web.UI.WebControls.TextBox
> {
> private const String CHECK_float_NAME = "floatValidate";
> protected override void OnPreRender(System.EventArgs e)
> {
> StringBuilder clientScript = new StringBuilder();
> base.OnPreRender(e);
> clientScript.Append("<script language='javascript'>");
> clientScript.Append("function " + CHECK_float_NAME + "()");
> clientScript.Append("{");
> clientScript.Append("if ((event.keyCode < 46) || (event.keyCode > 57) ||
> (event.keyCode==47))");
> clientScript.Append("event.returnValue = false;");
> clientScript.Append("}");
> clientScript.Append("</script>\r");
> Page.RegisterClientScriptBlock(CHECK_float_NAME,
> clientScript.ToString());
> }
> protected override void
> AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
> {
> base.AddAttributesToRender(writer);
>
> writer.AddAttribute("onkeypress", "return " + CHECK_float_NAME + "();");
> }
> }
> My Doubt is How to add Regular expression validators to my CS file of the
> Custom Control Textbox Which ll validate EMAIL Address.
>
> *Please Let me Know your suggestions*
>
> --
> Thanks in advance
> Sarvesh
>