<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function onPasteMe(pObj)
{
// validate pasted text
var input = window.clipboardData.getData('Text');
document.getElementById("txt1").value = input ;
var m= stripCharacters(input,pObj) ;
if(m)
{
input=input.replace(/[\s]/g,'\r');
var n=input.split(/\r/g).length;
alert(n);
}
}
function stripCharacters(input,pObj) {
var r = new RegExp("[^\\s\\r\\t\\n0-9]", "g");
var find = input.match(r) ;
if(find)
{
alert('String contains both alpha-numeric or your pre-defined special characters!');
pObj.innerHTML = "";
return false;
}
return true;
}
</script>
</head>
<body>
<textarea cols=19 id = "txt1" onPaste="onPasteMe(this);"></textarea>
</body>
</html>
如果我在文本区域中粘贴数字,如 1233445,则粘贴的值应显示在文本区域中,但如果我粘贴诸如 assdfsdf 123243' 或 2313adsdad 之类的值,则文本区域应自动清除???
i used below codes but its not worked for me please help,
pObj.innerHTML = "";
document.getElementById("txt1").value ="";