PDA

View Full Version : [CLOSED] Trying to remove character for TextField in Javascript on KeyPress.



Fahd
Jul 03, 2012, 2:14 PM
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>

Daniil
Jul 03, 2012, 6:17 PM
Hi,

Please use the MaskRe property.
http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.TextField-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>

Fahd
Jul 03, 2012, 6:29 PM
Thats better, but I need the user to enter a time, so how can I get the TextField to accept a colon ':' ?


Hi,

Please use the MaskRe property.
http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.TextField-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>

Daniil
Jul 03, 2012, 6:32 PM
You should change the MaskRe regular expression. Probably:

MaskRe="[0-9:]"

Fahd
Jul 03, 2012, 6:43 PM
That works, thanks...


You should change the MaskRe regular expression. Probably:

MaskRe="[0-9:]"