.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Validate TextBox Value on Paste Text

Posted By:Lakhan Pal Garg       Posted Date: September 17, 2009    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  
 

Validate TextBox Value on Paste Text. 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;
}

Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/

     

Further Readings:

Responses
Author: Ramesh         Company URL: http://www.dotnetspark.com
Posted Date: September 23, 2009

Nice Sir..you save my day...

Regards
Ramesh
Author: Lakhan Pal Garg         Company URL: http://www.dotnetspark.com
Posted Date: September 23, 2009

Hi Ramesh-

You are Welcome.

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend