end task from command line
Piece of possibly useful info.
If you need to end a task from the command line simply enter : taskkill /IM NameOfYourApp.exe
Very useful for updating things via Batch files.
Piece of possibly useful info.
If you need to end a task from the command line simply enter : taskkill /IM NameOfYourApp.exe
Very useful for updating things via Batch files.
Above is a HTTP Debugging Proxy that I have been introduced to. It is a very nice small little application that captures all the traffic between your pc and the web server of the site you are currently accessing. It shows the size of request, type of request and any HTTP codes if application. You can also view any sessions and a multitude of data. This is a great way to check exactly what gets sent to the user’s PC when they access the site.
Fiddler Site: http://www.fiddlertool.com/fiddler
Fiddler Download: http://www.fiddlertool.com/dl/FiddlerSetup.exe
Article: http://www.developer.com/lang/jscript/article.php/3631066
Fiddler Blog: http://insidehttp.blogspot.com/
I learnt something very interesting and useful today. If you want to see which websites link to yours, simply go to www.google.com and in the search criteria enter link:http://www.yourAddressHere.com and hit search. It works quite well.
Using regular expressions in ASP.Net is even easier than implementing them in plain html and yet few developers are using them. In this article I will show two ways of implementing Regular Expressions, using a Regular Expression Validator and using plain Javascript in ASP.Net. Both examples are very very simple. We will validate a telephone number and an email address.
How to Implement Regular Expressions in ASP.Net with Validator Controls.
1) Create a new a page in a web application project in visual studio.
2) Lets create a basic table with space for a Telephone Number, Email Address and submit button. Use the following code if you wish:
<table>
<tr>
<td>
Telephone Number:
</td>
<td>
<asp:TextBox runat=”server” ID=”txtTelNumber” />
</td>
<tr>
</tr>
</tr>
<tr>
<td>
Email Address:
</td>
<td>
<asp:TextBox runat=”server” ID=”txtEmail” />
</td>
<tr>
</tr>
</tr>
<tr>
<td colspan=”2″ style=”text-align:right”>
<asp:Button runat=”Server” ID=”btnSubmit” Text=”Submit” />
</td>
</tr>
</table>
3) Then, in the empty cells add RegularExpressionValidator Controls from your toolbox.
4) Give each of your validators a descriptive ID and specify the control that validator should check.
Now, for our telephone number validator we are going use the same expression that I used in my preveious post. Under the controls Properties, set the ValidationExpression = ^(\()?(011|012)(\)|-)?([0-9]{3})?([0-9]{4}|[0-9]{4})$
For the email validator, click on the (…)button in the ValidationExpression Box. A popup box will be presented, in this box you can enter your own custom validation OR select a predefined regEx. In this case select the Internet Email Address.
Do yourself a favour and enter your own custom error messages for both validators.
Now run the page and test it. The moment the user clicks the submit button it validates both fields and if the fields comply with their respective regular expressions then the postback will proceed HOWEVER, should either NOT comply with their regular expression the postback will not occur and the error message will be shown. Once a compliant Telephone Number and/or email address is entered, the error message will disappear and the user can submit the form again.
Here is the whole ASP.Net Code for the above example:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>
Telephone Number:
</td>
<td>
<asp:TextBox runat=”server” ID=”txtTelNumber” />
</td>
<td>
<asp:RegularExpressionValidator
ID=”regExTelephone” runat=”server” ControlToValidate=”txtTelNumber” Display=”Dynamic”
ErrorMessage=”Please enter a valid Telephone Number” ValidationExpression=”^(\()?(011|012)(\)|-)?([0-9]{3})?([0-9]{4}|[0-9]{4})$”></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
Email Address:
</td>
<td>
<asp:TextBox runat=”server” ID=”txtEmail” />
</td>
<td>
<asp:RegularExpressionValidator
ID=”regExEmail” runat=”server” ControlToValidate=”txtEmail” Display=”Dynamic”
ErrorMessage=”Please enter a valid Email Address” ValidationExpression=”\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td colspan=”2″ style=”text-align:right”>
<asp:Button runat=”Server” ID=”btnSubmit” Text=”Submit” />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
How to Implement Regular Expressions in ASP.Net using BLOCKED SCRIPT
1) Create a new a page in a web application project in visual studio.
2) Lets create a basic table with space for an Email Address and submit button. Use the following code if you wish:
<table>
<tr>
<td>
Email Address:
</td>
<td>
<asp:TextBox runat=”server” ID=”txtEmail” />
</td>
</tr>
<tr>
<td colspan=”2″ style=”text-align:right”>
<asp:Button runat=”Server” ID=”btnSubmit” Text=”Submit” />
</td>
</tr>
</table>
3) In the your header tags create a script block and write the neccessary functions to check the email entry. You can use the following script:
<script type=”text/javascript”>
function ValidateEmail()
{
//Declare regular expression
var re = new RegExp(’^.+@[^\.].*\.[a-z]{2,}$’);
if (window.document.getElementById(’txtEmail’).value.match(re))
{
//allow postback to continue
return true;
}
else
{
//inform user that the Telephone Number is not valid
alert(”Email not valid”);
//Set the focus on non-compliant field
window.document.getElementById(’txtEmail’).focus();
//Prevent the postback
return false;
}
}
</script>
4) Then simply add the following attribute to your submit button:
OnClientClick=”BLOCKED SCRIPTreturn ValidateEmail();”
Here is the full code for this page:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
<script type=”text/javascript”>
function ValidateEmail()
{
//Declare regular expression
var re = new RegExp(’^.+@[^\.].*\.[a-z]{2,}$’);
if (window.document.getElementById(’txtEmail’).value.match(re))
{
//allow postback to continue
return true;
}
else
{
//inform user that the Telephone Number is not valid
alert(”Email not valid”);
//Set the focus on non-compliant field
window.document.getElementById(’txtEmail’).focus();
//Prevent the postback
return false;
}
}
</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>
Email Address:
</td>
<td>
<asp:TextBox runat=”server” ID=”txtEmail” />
</td>
</tr>
<tr>
<td colspan=”2″ style=”text-align:right”>
<asp:Button runat=”Server” ID=”btnSubmit” OnClientClick=”BLOCKED SCRIPTreturn ValidateEmail();” Text=”Submit” />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
And there we go. Now nobody who has read can say they don’t know how to implement Regular expressions. I realised that this isn’t the most complete guide to regular expressions but Rome wasn’t built in a day. This is aimed at those people who have never in their lives implemented a Regular Expression.
I would appreciate any feedback and/or suggestions you may have on this or even requests pertaining to Regular Expressions.
Recently Brian Johnson posted something that made me think. There are hundreds and probably thousands of web developers out there who have never used regular expressions and even if the knew about them they don’t know HOW to implement them. Regular expressions are really awesome once you start using them. They are exceptionally powerful although they look really difficult in the beginning. For the beginners I suggest that you visit a site like http://www.regular-expressions.info/ as they have many many examples and a very good tutorial. Once you have some idea of whats cooking then bookmark http://regexlib.com/CheatSheet.aspx. Between these two sites you’ll be writing your own regular expressions in no time. But then again, why re-invent the wheel? Visit http://regexlib.net/ for a whole range regular expressions!
So what is a regular expression? It is a set of rules that a certain set of text must adhere to. For example, if we want to test whether a user has entered a valid Johannesburg or a Pretoria telephone number. Most developers first test whether the number contains 011 or 012 as the area code. Then if that was successful test whether the user entered 7 other digits. This would usually comprise of a few “if” statements and hopelessly too much code. Whereas with a regular expression if can be done with 1 line of code.
I am going to write this example using only Javascript and tomorrow I will post an entry using ASP.Net.
<script type=’text/javascript’>function ValidateNumber()
{
//Declare regular expression
var re = new RegExp(’^(\()?(011|012)(\)|-)?([0-9]{3})?([0-9]{4}|[0-9]{4})$’);
if (window.document.getElementById(’txtTelephoneNumber’).value.match(re))
{
alert(”Valid telephone Number”);
}
else
{
alert(”Telephone Number not valid”);
}
}
</script>
and thats it! One line and it checks whether the entered number is in the following format: 0128134456 or 0118176543. Isn’t that so much easier? You can use regualr expressions to check the validity of telelphone numbers, email addresses, URI’s, date/times and anything else. Creating your own complex regular expression’s may take a while to master but it’ll save countless hours of redudant coding.
Here’s the full code for a quick test page. Just paste it in notepad and save the file as a .html file and open with Internet Explorer.
<html>
<head>
<script type=’text/javascript’>
function ValidateNumber()
{
//Declare regular expression
var telRegEx = new RegExp(’^(\()?(011|012)(\)|-)?([0-9]{3})?([0-9]{4}|[0-9]{4})$’);
//Match textbox value to Regular Expression
//Match method returns a boolean value
if (window.document.getElementById(’txtTelephoneNumber’).value.match(telRegEx))
{
alert(”Valid telephone Number”);
}
else
{
alert(”Telephone Number not valid”);
}
}
</script>
<head>
<body>
<span>Enter a telephone number: </span><input type=’text’ id=’txtTelephoneNumber’ /><br /><br />
<input type=’button’ onclick=”ValidateNumber();” value=”Test Number” />
</body>
</html>
I firmly believe that any web developer should be using regular expressions for client side input validation. It’ll save you time and improve your application’s performace since you won’t need to do your validations client side. This is something that is exceptionally easy and easy to implement. The .Net implementation is even easier but I’ll post that tomorrow tonight!
You can read Brian’s post about Regular Expressions here: Do Regular Expressions scare developers?
Well, after some hosting issues I’m finally up again. So for the usual lame introduction to their blog, here it goes. I’m a Software Developer specializing in ASP.Net and C#. This blog will mainly contain articles relating to development, my thoughts on gaming and music. In the meantime, I’m going to start copying my posts from my old blog at DotNet.org.ZA (http://dotnet.org.za/trivium).
 Only reason I moved my blog is to start trading under my own name. The blog was originally created when I worked at a previous company with incredibly strict IP(Intellectual Property) rules. I hope you enjoy my content! Please mail me with any comments or just comment on each post.