PDA

View Full Version : [CLOSED] Avoid user inserting some character in textfield



profitsistemas
Feb 07, 2013, 3:53 PM
I have a problem that i can not solve. I have a textArea and I need to prevent user for introducing character \. I have read that I need to use MaskRe property but I can not make it to work.

Daniil
Feb 07, 2013, 5:32 PM
Hi @profitsistemas,

Please take a look at the example.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TextField runat="server" MaskRe="[a-zA-Z0-9]" /> <%-- You might need to extend this RegExp with other characters --%>
<%--Though, maybe, there is a simple way to get a RegExp which would match all except "\". I am not sure. --%>

<ext:TextField runat="server" EnableKeyEvents="true">
<Listeners>
<KeyPress Handler="var charCode = String.fromCharCode(e.getCharCode());

if(/\\/.test(charCode)){
e.stopEvent();
}" />
</Listeners>
</ext:TextField>
</form>
</body>
</html>

Vladimir
Feb 07, 2013, 5:42 PM
Please use the following MaskRe to prevent '\' symbol


MaskRe="[^\\]"

profitsistemas
Feb 07, 2013, 6:48 PM
Adding MaskRe="[^\\]" doesn't allow me to enter character \ which is ok, but it lets me copy some text with \ and then paste this into field. I need this field to be invalid if it has any \.

Baidaly
Feb 08, 2013, 12:24 AM
Hello!

To make this field invalid you should create own validation type: http://examples2.ext.net/#/Form/Validation/Custom_VType/

profitsistemas
Feb 08, 2013, 1:07 AM
Ok, thanks I will try some code related to example.