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
}
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.
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@#$&~`]+$")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With