...

View Full Version : Restricting users from pasting into textbox..?



murali1983
02-05-2007, 04:39 AM
Hi

i have validations done for the text box..
a textbox can accept only numbers, so onkeypress if the key is number i return true else false.....this works fine if the user is entering into textbox..instead if the users copy pastes somethin then it wont...

so how can i restrict a user form pasing text into textbox...??

thnx
murali

liorean
02-05-2007, 05:21 AM
Wouldn't it be better if you used the change event on the form control to validate the input, tell the user what's wrong some way and what is the correct format?

murali1983
02-05-2007, 05:43 AM
ok...
but now i cant change it...coz i have used it in many places...
is ther any attribute using which i can restrict the users from pasting......

vwphillips
02-05-2007, 08:52 AM
I did not write this


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

var Txt=[''];

function RecordTxt(obj){
setTimeout(function(){ RecordTxtDo(obj); },100);
}

function RecordTxtDo(obj){
Txt=[obj.value||'',obj];
}

function CheckTxt(obj){
if (obj==Txt[1]&&obj.value.length>Txt[0].length){
alert('No Pasting');
obj.value=Txt[0];
}
}
//-->
</script></head>

<body>

<input onmouseover="RecordTxt(this)" onfocus="RecordTxt(this)" onkeyup="RecordTxt(this)" onmouseout="CheckTxt(this)" onblur="CheckTxt(this)" >
<input onfocus="RecordTxt(this)" onkeyup="RecordTxt(this)" onmouseout="CheckTxt(this)" onblur="CheckTxt(this)" >
onkeyup="RecordTxt(this)"

</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum