Validate text expression without RegularExpressionValidator server side

Hi,

To validate the text expression without using regular expression validator on your code behind (i.e. on server side- .cs), use following code:

bool validText= System.Text.RegularExpressions.Regex.IsMatch(“Your Text”, “Your Expression”)

for example, I need to validate value of Email Address text box of the submission form:

bool validEmailId=System.Text.RegularExpressions.Regex.IsMatch(txt_emailid.Text,

\\w+([-+.’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*);

That’s it..

Enjoy Coding 🙂


Test Connection To host / Is host reachable / PING functionality C#

Hi,

We can check the particular machine is get ping or not from using C# code.
Also, we can get the Round-triptime of packet.
Using Ping and PingReply class, we can do this.

The code is as below

Ping x = new Ping();
PingReply reply = x.Send(IPAddress.Parse("192.168.1.1")); //enter ip of the machine
if (reply.Status == IPStatus.Success) // here we check for the reply status if it is success it means the host is reachable
{
status.Text = "Available. And Round Trip Time of the packet is:"+reply.RoundtripTime.ToString();
}
else //if host is not reachable.
status.Text = "Not available";

Just 3-4 lines will solve the issue.

That’s it.
Enjoy Coding.. 🙂