Validate Textbox Value for Special Character Paste Data

JavaScript Method to Validate '<' and '>' Character on paste data in text box or in Text Area.
Read the Text from clipboard and validate using ValidateText Function.
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;
}

0 comments: