[CLOSED] Trying to remove character for TextField in Javascript on KeyPress.

  1. #1

    [CLOSED] Trying to remove character for TextField in Javascript on KeyPress.

    Since the Masking is not available right now, I'm trying to remove the non-numeric character for Time.

    Need to remove when Non-Numeric !!

    If you have a different approach, please advice ?

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" TagPrefix="ext" Namespace="Ext.Net" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Example of Issue </title>
        <script type="text/javascript">
    
            var isNumberKey = function() {
                var key = event.keyCode;
                if (key >= 48 && key <= 57) {
                    alert("Numeric");
                    return true;
                }
                alert("Non-Numeric");
                return false;
            }
     
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <asp:ScriptManager runat="server" />
        <br />
        <ext:TextField ID="TextField1" runat="server" Width="45" AllowBlank="false" Text="00:00"
            EnableKeyEvents="true" MaxLength="5">
            <Listeners>
                <KeyPress Fn="isNumberKey" />
            </Listeners>
        </ext:TextField>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jul 04, 2012 at 11:02 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Please use the MaskRe property.
    http://docs.sencha.com/ext-js/3-4/#!...eld-cfg-maskRe

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:TextField runat="server" MaskRe="[0-9]" />
    </body>
    </html>
  3. #3
    Thats better, but I need the user to enter a time, so how can I get the TextField to accept a colon ':' ?

    Quote Originally Posted by Daniil View Post
    Hi,

    Please use the MaskRe property.
    http://docs.sencha.com/ext-js/3-4/#!...eld-cfg-maskRe

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:TextField runat="server" MaskRe="[0-9]" />
    </body>
    </html>
  4. #4
    You should change the MaskRe regular expression. Probably:
    MaskRe="[0-9:]"
  5. #5
    That works, thanks...

    Quote Originally Posted by Daniil View Post
    You should change the MaskRe regular expression. Probably:
    MaskRe="[0-9:]"

Similar Threads

  1. [CLOSED] TextField KeyPress handler for the Backspace key
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Mar 15, 2012, 1:01 PM
  2. textfield keypress listeners
    By okutbay in forum 1.x Help
    Replies: 3
    Last Post: May 04, 2010, 2:39 AM
  3. [CLOSED] Add mask to textfield keypress
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 26, 2010, 4:46 PM
  4. Replies: 2
    Last Post: Mar 18, 2010, 11:36 AM
  5. [CLOSED] How to add tab and remove tab in javascript
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 10, 2008, 2:02 AM

Tags for this Thread

Posting Permissions