Thursday, June 16, 2011

Javascript validation

I have posted the code of validate positive integer and floating point value in javascript.


You can remove condition parseInt(value)<=0 and parseFloat(value)<=0 respectively to allow positive as well negative integer and floating values to your customer.


function checkforInteger(value)

{

//alert(parseInt(value));

if (parseInt(value) != value || parseInt(value)<=0)

{

return false;

}

else

{

return true;

}

}

//Returns true if given input is valid float else return false

function checkforPrice(value)

{

if (isNaN(parseFloat(value)) || parseFloat(value)<=0)

{

return false;

}

else

{

return true;

}

}


Enjoy!

No comments:

Post a Comment