简体   繁体   English

如何限制ext js文本字段中的特定字符?

[英]how to restrict specific characters in ext js textfield?

how to restrict specific characters(like apostrophe, !, ^ etc) in ext js textfield to enter with key strokes? 如何限制ext js文本字段中的特定字符(如撇号,!,^等)以键击输入? I used below code which allows only mentioned characters 我使用下面的代码,只允许提到的字符

{
xtype:"textfield",
maskRe: new RegExp("[a-zA-Z1-9_\s@#$&~`]+$"),
allowBlank : false
}

To specify restricted characters instead of allowed characters simply prepend a ^ inside the square brackets, which means "any character except...": 要指定受限制的字符而不是允许的字符,只需在方括号内添加^ ,这意味着“除了......之外的任何字符”:

maskRe: /[^!\^]/

(= any character except ! and ^ ) (=除了!^之外的任何字符)

Also see this fiddle . 也看到这个小提琴

Also note that it's not necessary to use operators like + , ^ and $ because the regular expression used with maskRe is tested against each single character about to be entered, not against the value of the field. 另请注意,不必使用+^$等运算符,因为与maskRe使用的正则表达式针对要输入的每个单个字符进行测试,而不是针对字段的值。

您需要添加行^ anchor的开头,以便检查确切的字符串匹配,并且还需要再次转义反斜杠。

new RegExp("^[a-zA-Z1-9_\\s@#$&~`]+$")

You can refer to vtype properties for the Ext Js component TextField. 您可以参考Ext Js组件TextField的vtype属性。 vtype V型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM