Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > RadTextBox + Accept only Alphabets
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered RadTextBox + Accept only Alphabets

Feed from this thread
  • Leo avatar

    Posted on Mar 7, 2009 (permalink)

    Hi,

       I am using a RadTextBox, On that i have to allow the user to enter only the alphabets.

      Pls any one guid me...

    Leo.

  • Daniel Daniel admin's avatar

    Posted on Mar 9, 2009 (permalink)

    Hello Leo,

    You can either use RadMaskedTextBox control or use regular expressions to validate the input:
    <script type="text/javascript" language="javascript"
        function keyPress(sender, args) 
        { 
            var text = sender.GetValue() + args.KeyCharacter; 
            if (!text.match('^[^0-9]+$')) 
                return false; 
        } 
    </script> 
    <rad:RadTextBox ID="RadTextBox1" runat="server"
        <ClientEvents OnKeyPress="keyPress" /> 
    </rad:RadTextBox> 

    Kind regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  • Casey Master avatar

    Posted on Oct 28, 2009 (permalink)

    This is not working for me with a RadTextBox. I can still enter numbers and special characters. I need the RadTextBox to only allow ALPHA (a-z, A-Z) characters. I'm using IE 6 and RadControls version 2009.1.311.20.

    <telerik:RadTextBox ID="RadTextBox1" runat="server">  
    <ClientEvents OnKeyPress="keyPress" /> 
        </telerik:RadTextBox> 

    function keyPress(sender, args) {  
                var text = sender.GetValue() + args.KeyCharacter;  
                if (!text.match('^[^0-9]+$'))  
                    return false;  
            }  

    Thanks,
    Casey

  • Casey Master avatar

    Posted on Oct 29, 2009 (permalink)

    I was able to achieve my desired functionality by calling the following Javascript on the 'OnKeyPress' event of the RadTextBox.

    function AlphabetOnly(sender, eventArgs) {  
                var c = eventArgs.get_keyCode();  
                if ((c < 65) ||  
                    (c > 90 && c < 97) ||  
                    (c > 122))  
                    eventArgs.set_cancel(true);  
            } 

  • Sebastian Sebastian admin's avatar

    Posted on Oct 29, 2009 (permalink)

    Hello Casey,

    Thank you for posting your solution in this public forum thread - thus you can help other community members who are searching for a similar implementation. I updated your Telerik points for the involvement.

    Best regrads,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

  • Casey Master avatar

    Posted on Oct 29, 2009 (permalink)

    Thanks Sebastian. I know it took a lot of searching and frustration to find a solution.

    I don't know how many people would use a property like an Alpha only property, but I think it would be a good addition to the RadTextBox. Maybe have a property like - Format, then values of default (accepts any character), alpha only, and alpha-numeric. Just a thought.

    Casey

  • praveen kumar avatar

    Posted on Jun 17, 2010 (permalink)

    hi
    With this code, it blocks the 'back space' and 'tab order'.
    Please post the solution for tab order and back space with this code.

    Thanks and regards
    Praveen Kumar. P

  • Dhruval Dave avatar

    Posted on Apr 21, 2011 (permalink)

    As soon as Numeric Text Enters I Want to Make Textbox Border Red...
    How to Do that .
    Please Help

  • Posted on May 18, 2011 (permalink)

    The above solution by Daniel works for me until the user paste special characters in textbox. How can I restrict user from entering special characters if its a copy/paste or right click and paste?

  • Posted on May 20, 2011 (permalink)

    Hello Irfan,

    Try this approach.
    aspx:
    <telerik:RadTextBox  ID="RadTextBox1"  runat="server"
      oncopy="return false" onpaste="return false"  oncut="return false"/>

    Thanks,
    Princy.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > RadTextBox + Accept only Alphabets