RSS

Tag Archives: c#

Regular Expressions Patterns


RegExp

  • Integer (positive and negative)
    • ^[+-]?\d+$
    • ^[+-]?[0-9]+$
    • Matches: any signed integer
  • Integer (positive)
    • ^[0-9]+$
    • Matches: any positive signed integer
  • Integer (negative)
    • ^[-][0-9]+$
    • Matches: any negative signed integer
  • Decimal (positive and negative)
    • ^[-+]?\d+(\.\d+)?$
    • ^[+-]?[0-9]*(?:\.[0-9]*)?$
    • Matches: 123 | -123.45 | +123.56
  • Decimal (positive)
    • ^[+]?[0-9]*(?:\.[0-9]*)?$
    • Matches: 123 | 123.45 | +123.56
  • Decimal (negative)
    • ^[-][0-9]*(?:\.[0-9]*)?$
    • Matches: -123 | -123.45 | -123.56
  • Number (positive and negative)
    • ^[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)([eE][+-]?[0-9]+)?$
    • Matches: 23 | -17.e23 | +.23e+2  
  • Natural Number
    • ^[0-9]*[1-9]+$|^[1-9]+[0-9]*$
  • Alphabetical
    • [^a-zA-Z]
    • Matches: ABC | Test | xyz
  • Alphanumeric
    • [^a-zA-Z0-9]
    • ^[a-zA-Z0-9_]*$
    • Matches: ABC | Test123
  • E-Mail
    • ^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
    • Matches: AhmedNegm@WindowsLive.com
  • Date
    • ^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$
    • Matches: this expression validates a date field in dd/mm/yyyy  and mm/dd/yyyy format
  • Temperature
    • ^[-+]?\d*(\.\d+)?( )?(Celsius|C|c|CELSIUS|Fahrenheit|F|f|FAHRENHEIT|Kelvin|K|k|KELVIN)?$
    • Matches: 34F | 56 Celsius | 22C
  • Egyptian National ID
    • (2|3)[0-9][1-9][0-1][1-9][0-3][1-9](01|02|03|04|11|12|13|14|15|16|17|18|19|21|22|23|24|25|26|27|28|29|31|32|33|34|35|88)\d\d\d\d\d
  • Egyptian Mobile Number
    • (201)[0-9]{9}
  • Hexadecimal String
    • ^[0-9A-Fa-f]+$
    • Matches: 062706440644064700200623064306280631
 
 

Tags: , , , , , , , , , , , , , , , , , , ,

Bulk Insert into SQL Server using C#


multiple-files

I was recently tasked with a project at my work to update SQL Server database with large amounts of data each hour. Every hour, I’ve got an text file contains more than 500,000 records and there were several that needed processing daily. 

Read the rest of this entry »

 
Leave a comment

Posted by on July 17, 2013 in ASP .NET, Visual C# . NET

 

Tags: , , , , , , , , , , , , ,

Strong Name in .NET !


This content copied from MSDN !

Strong Name consists of the assembly’s identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature. It is generated from an assembly file (the file that contains the assembly manifest, which in turn contains the names and hashes of all the files that make up the assembly), using the corresponding private key. Visual Studio can assign strong names to an assembly. Assemblies with the same strong name are expected to be identical.

Strong Name (further referred to as “SN”) is a technology introduced with the .NET platform and it brings many possibilities into .NET applications. But many .NET developers still see Strong Names as security enablers (which is very wrong!) and not as a technology uniquely identifying assemblies. Strong Name is a technology based on cryptographic principles, primary digital signatures.

Read the rest of this entry »

 
1 Comment

Posted by on April 20, 2013 in Visual C# . NET

 

Tags: , , , , , , , , , , , , ,

Visual Studio 2010 Code Snippets !!


code1

Code snippets are small blocks of reusable code that can be inserted in a code file using a context menu command or a combination of hot-keys. They typically contain commonly-used code blocks such as try-finally or if-else blocks, but they can be used to insert entire classes or methods.

Read the rest of this entry »

 
Leave a comment

Posted by on January 15, 2013 in Visual Basic .NET, Visual C# . NET

 

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Dynamic keyword in C# 4.0 !!


image9_207

You have to read or know more about DLR (Dynamic Language Run-time) from here (DLR)

The introduction of static type checking represented an  important milestone in the history of programming languages. In the 1970s, languages such as Pascal and C started enforcing static types and strong type checking. With static type checking, the compiler will produce an error for any call that fails to pass a method argument of the appropriate type. Likewise, you should expect a compiler error if you attempt to call a missing method on a type instance.

Other languages that push forward the opposite approach—dynamic type checking—have come along over the years. Dynamic type checking contradicts the idea that the type of a variable has to be statically determined at compile time and can never change while the variable is in scope. Note, however, that dynamic type checking doesn’t confer wholesale freedom to mix types, pretending they’re the same. For example, even with dynamic type checking, you still can’t add a Boolean value to an integer. The difference with dynamic type checking is that the check occurs when the program executes rather than when it compiles.

Read the rest of this entry »

 
Leave a comment

Posted by on October 10, 2012 in Visual Basic .NET, Visual C# . NET

 

Tags: , , , , , , , ,

Passing & Streaming images to CrystalReport at run-time !!


Sometimes, you want to make something abnormal in your application. One of these abnormal actions that you want to pass an image to your report (CrystalReport) at run-time stage of your application.

There are many articles and resources have been written in this topic, but all are complicated and take a hard code to do with incomplete way. You can follow the pictures to see how this ??

Read the rest of this entry »

 

Tags: , , , , , , , , , , , , , , , , , ,

How to stop “Ding” sound when pressing “Enter” in TextBox


Very simple way to remove the annoying beep sound from pressing enter in a single-line text box, for example in a console, or login form. Very simple, no multiline, and the sounds gone!

private void txtValue_KeyUp(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        e.SuppressKeyPress = true;
    }
}
//////////////////////////
private void txtValue_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Enter)
    {
        e.Handled = true;
    }
}
 
Leave a comment

Posted by on August 4, 2012 in Visual C# . NET

 

Tags: , , , , , , ,