Reputation: 96
how to restrict specific characters(like apostrophe, !, ^ etc) in ext js textfield to enter with key strokes? I used below code which allows only mentioned characters
{
xtype:"textfield",
maskRe: new RegExp("[a-zA-Z1-9_\s@#$&~`]+$"),
allowBlank : false
}
Upvotes: 3
Views: 7691
Reputation: 4047
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.
Upvotes: 8
Reputation: 319
You can refer to vtype properties for the Ext Js component TextField. vtype
Upvotes: 1
Reputation: 174844
You need to add start of the line ^
anchor so that it would check for an exact string match and also you need to escape the backslash one more time.
new RegExp("^[a-zA-Z1-9_\\s@#$&~`]+$")
Upvotes: 2