Validate TextBox Value on Paste Text

Lakhangarg
Posted by Lakhangarg under JavaScript category on | Views : 4313
function OnTextPaste()
{
var data="";
data=window.clipboardData.getData("Text");
if(data)
{
var ret=ValidateText(data);
if(!ret)
alert('Sorry, you can not paste text having <, > in it.');
return ret;
}
else
return false;
}

function ValidateText(str)
{
var ret;
if(str.indexOf('<') != -1)
ret=false;
else if(str.indexOf('>') != -1)
ret=false;
else
ret=true;
return ret;
}


Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/

Comments or Responses

Login to post response