How do I restrict certain characters in an ext js textbox?

how to restrict certain characters (like apostrophe,!, ^, etc.) in an ext js textbox for input with keystrokes? I used below code which only allows the specified characters

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

      

+3


source to share


3 answers


To specify restricted characters instead of valid characters, simply enclose ^

in square brackets, which means "any character except ...":

maskRe: /[^!\^]/

      

(= any character except !

and ^

)



Also see this fiddle .

Also note that it is not necessary to use operators such as +

, ^

and $

, because the regexp used with is maskRe

checked for every single character that needs to be entered, not the field value.

+6


source


You need to add the beginning of the ^

anchor line so that it checks for exact line matches, and also you need to escape the backslash again.



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

      

+2


source


You can reference vtype properties for Ext Js TextField component. vtype

+1


source







All Articles