Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Restricting users from pasting into textbox..?

    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

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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......

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    I did not write this
    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •