Wednesday, September 16, 2009

restrict Backspace and Delete in textbox

// This is for the Key Press Event
function Keypress_Event()
{
// This is for Getting the Source Element..
var objTxtBox = window.event.srcElement;
// declare the variable for the bool value.
var isOk = false;
// Here we need not backspace keycode = 8 and the delete keycode 46
isOk = ( event.keyCode == 8 || event.keyCode == 46 ) ? false:true; event.returnValue=isOk;
} And in your aspx call the keypress as

asp:TextBox ID="txtTest" runat="server" onkeydown="Keypress_Event()"

Wednesday, August 12, 2009

Get a Filename from a Path in Javascript

Here's a quick Javascript function that will parse the filename from a path using regex. It looks for any letter or digit, hyphen, or underscore followed by a dot (.) followed by a letters or numbers for the extension.

function getFileName(path) {
return path.match(/[-_\w]+[.][\w]+$/i)[0];
}