Monday, July 20, 2009

Java Script :Trim and MoneyOnly

function trimThis(value1)
{
value1= value1.replace(/^\s+|\s+$/, '');
return value1;
}



function moneyonly(e)
{
var unicode=e.charCode? e.charCode : e.keyCode;
var st = document.getElementById("amount").value;
//alert(unicode)
if (unicode== 8)
{
return true;
//if the key isn't the backspace key (which we should allow)
}
else if(unicode == 46)
{

if(st.toString().indexOf(".",0) != -1)
{
return false;
}

}
else if (unicode<48||unicode>57) //if not a number
{

return false //disable key press
}
else if(st.toString().indexOf(".",0) != -1)
{
if(st.toString().length - st.toString().indexOf(".",0) > 2)
{
return false;
}
}

return true;
}