Tuesday, April 24, 2007

Regular Expressions
the following codes in this article throws light to some of the commonly used regular expression..all are coded with c#,asp.net

How to Find a text and Replace with other text
string FindAndReplace(string text)
{
string str = text;
Regex rgx = new Regex( class="str">@"\bbuddha\b");
if (rgx.IsMatch(text))
{
str = rgx.Replace(str, "mybuddha");
}
return str;
}


Testing complexity of password using regular expression validator
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="RegularExpressionValidator" ValidationExpression="(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,15}"></asp:RegularExpressionValidator></div>


Splitting comma seperated files with a br tag
string SplitLine(string text)
{
string str = text;
Regex rgx = new Regex(@",\s*");
if (rgx.IsMatch(text))
{
str = rgx.Replace(str, ",<br>" );
}
return str;
}

SplitLine("Microsoft,Linux,Oracle");
will return
Microsoft,
Linux,
Oracle




Extracting Query Strings from URLs
Regex rgx= new Regex( "\\?(?<query>[^<>#\"]+)" );




Extracting Filenames from Paths
Regex rgx = new Regex( ?
"(?<path>(\\\\(?<file>[^\\\\/:*?\"<>|.][^\\\\/:*?\"<>|]*))+)" );




Extracting Extensions from Filenames
Regex rgx = new Regex( ?
"\\\\[^\\\\/:*?\"<>|]+\\.(?<ext>[^.\\\\/:*?\"<>|]+)" );




Formatting U.S. Dates
Regex rgx = new Regex( @"^(\d{1,2})[-\/.]?(\d{1,2})[-\/.]?((?:\d{2}|\d{4}))$" );




Formating Dates
string FormatDates(string text)
{
string str = text;
Regex rgx = new Regex(@"(?:(?<=^)|(?<=[^\d]))(\d)(?=[^\d])");

if (rgx.IsMatch(text))
{
str = rgx.Replace(str, @"0$1");
}

return str;

}
1/1/2007 will become 01/01/2007




Validating Credit Card Numbers
<asp:RegularExpressionValidator Id="revInput" RunAt="server"
ControlToValidate="txtInput"
ErrorMessage="Please enter a valid value"
ValidationExpression="^(\d{4}-){3}|(\d{4} ){3}\d{4}|\d{15,16}|?
\d{4} \d{2} \d{4} \d{5}|\d{4}-\d{2}-\d{4}-\d{5}$"
>
</asp:RegularExpressionValidator>




Validating Dates in MM/DD/YYYY Format
<asp:RegularExpressionValidator Id="revInput" RunAt="server"
ControlToValidate="txtInput"
ErrorMessage="Please enter a valid value"
ValidationExpression="^(0?2/(0?[1-9]|[12][0-9])|
(0?[469]|11)/(0?[1-9]|[12][0-9]|30)|
(0?[13578]|1[02])/(0?[1-9]|[12][0-9]|3[01]))/\d{4}$"
>
</asp:RegularExpressionValidator>



Monday, April 23, 2007

Microsoft Expression





Microsoft Expression is a suite of graphics programs from Microsoft aimed at developers and designers. It consists of four products:

Microsoft Expression Web (code-named Quartz) - A program for designing web sites.
Microsoft Expression Blend (code-named Sparkle) - A program for designing user interfaces based on Windows Presentation Foundation.
Microsoft Expression Design (code-named Acrylic) - A program for editing graphics. Design edits both raster and vector graphics.
Microsoft Expression Media - A program to manage digital assets and media.

more info

Sunday, April 22, 2007

Posting Data to a 3rd party page in .net

situations arise when we need to post data from our form to other asp,jsp pages...

we need to handle this situation differently

i have added a sample code which takes the value for the TextBox and it will transfer the datas to a different page where the data from the TextBox will be processed.


System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");

System.Web.HttpContext.Current.Response.Write("</head><body onload=\"document.Form1.submit()\">");



//transfer the control to http://mysite/WebForm2.aspx

System.Web.HttpContext.Current.Response.Write("<form name=\"Form1\" method=\"post\" action=\"http://localhost/ee/WebForm2.aspx\" >");



//add the value of the text box to a hidden control

System.Web.HttpContext.Current.Response.Write("<input name=\"txtname\" type=\"hidden\" value=\"" + TextBox1.Text + "\">");

System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");
System.Web.HttpContext.Current.Response.End();

Friday, April 20, 2007

Microsoft Silver Light



Silverlight is a cross-browser, cross-platform plug-in for delivering the next generation of media experiences and rich interactive applications (RIAs) for the Web.

more info

Sunday, April 08, 2007

Copy Text To Clip Board Using Java Script


<script type="text/javascript">
function ClipBoard()
{
window.clipboardData.setData("Text", document.getElementById('TextBox1').value);
var text = window.clipboardData.getData("Text");

}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server">Text to copy here</asp:TextBox><br />
<br />
<input id="Button1" type="button" value="Copy to Clipboard" onclick="ClipBoard()" />

</div>
</form>
</body>
</html>