View Full Version : [Solved]Textfields for specific Character

12 Jun 2011, 7:40 AM
How to setting textfields that can only be edited by a specific character?
(ex. number)

Solved: Iam using this code for textfield

maskRe: /^([0-9])$/

Thanks for "skirtle";)

12 Jun 2011, 8:43 AM
This is covered in the introduction in the docs:


maskRe and stripCharsRe.

If you're specifically interested in numbers then see:


If you click the 'Hide Inherited Members' button (blue up arrow with red minus, top-right toolbar) it'll show you specific settings for number configuration.

14 Jun 2011, 3:12 AM
I was used numberfield before, but when I entry data like this "196411051990031003" it goes "196411051990031000".
003 to 000, any advice? And how to make textfield just for number character?


16 Jun 2011, 10:40 AM
You cannot represent such large integers precisely using numbers in JavaScript, as you've observed you get rounding. Do you really need such big numbers? If you do then you'll need to keep them as strings.

As for implementing your own number-only TextField, I suggest you have a read of the source code for NumberField:


The initEvents() method is particularly relevant but all it does is use the config options I mentioned previously.

17 Jun 2011, 10:09 PM
But, how I can implement textfield for number with baseChars?

18 Jun 2011, 9:27 AM
Just use a maskRe of /\d/ and a stripCharsRe of /^\D*0+(?=.*\d)|\D/g.

18 Jun 2011, 6:23 PM
Just use a maskRe of /\d/ and a stripCharsRe of /^\D*0+(?=.*\d)|\D/g.

Hows that work? When I implemented that, just char "d" that I can typed...

18 Jun 2011, 6:41 PM
\d matches a numeric digit whereas just d would match the letter d, I can only assume you've typed it in wrong. Regular expressions are bread-and-butter programming, please read a tutorial so that you can fix trivial mistakes like this by yourself.

Try copy and paste to make sure you type it in right:

new Ext.form.TextField({
maskRe: /\d/,
renderTo: Ext.getBody(),
stripCharsRe: /^\D*0+(?=.*\d)|\D/g

18 Jun 2011, 6:45 PM
I was followed ur advice, but it same as before.

18 Jun 2011, 7:14 PM
The only thing I can think of is that whatever browser you are using doesn't support \d and \D. I can't find any mention of this online, nor do any of the browsers I have exhibit this problem, including IE6.

On the off chance it is that, you could use the character classes of [0-9] and [^0-9] to replace them. I repeat, please read a tutorial.

18 Jun 2011, 8:14 PM
I'm very sorry, skirtle.... But I cant understand that tutorial say.... Sorry. Thank you very much.... :D