www.webdeveloper.com
Results 1 to 5 of 5

Thread: On Paste

  1. #1
    Join Date
    Aug 2005
    Posts
    25

    On Paste

    I used this code for validate text box when user paste values to the text box.
    Code:
    //Browser Detection
    var strUserAgent = navigator.userAgent.toLowerCase(); 
    var isIE = strUserAgent.indexOf("msie") > -1; 
    var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
    var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 
    
    
    function Paste(objEvent) {
    var objInput;
    if (isIE) 
    {
    objInput = objEvent.srcElement; 
    }
    else 
    {
    objInput = objEvent.target;
    }
    if (!/^[A-Za-z0-9\s\\$]*$/.test(objInput.value)) {
    alert("The character you attempted to used is not allowed for this field.");
    objInput.value = objInput.validValue || "";
    objInput.focus();
    objInput.select(); 
    } else {
    objInput.validValue = objInput.value;
    }
    }

    It works in other characters but if I paste '', program did not allow to paste it. How can I solove this problem.
    Thanks.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Remove text in red:
    Code:
    if (!/^[A-Za-z0-9\s\\$]*$/.test(objInput.value)) {

  3. #3
    Join Date
    Aug 2005
    Posts
    25
    I want to paste '' value in to the textbox. how can I do this?

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Sorry, read your post too quickly:
    Code:
    if (!/^[A-Za-z0-9\s\xA3\$]*$/.test(objInput.value)) {

  5. #5
    Join Date
    Aug 2005
    Posts
    25
    Thanks it works.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles