View Full Version : Custom Validation: vtype for validating positive integer

8 Apr 2011, 2:31 AM
Hello everybody,

I need a favor, but I don't know if this is the right forum place.

I'm using the 3.3 Ext Js version and I would like to validate a field inside a FormPanel where the users can type only positive integer.

Looking for a bit on the internet I need to create new custom vtype and this is my code:

Ext.apply(Ext.form.VTypes, {

IntNum: function(v) {
return /^[0-9]$/i.test(v);

IntNumText: 'Must be a positive integer',

IntNumMask: /[a-z0-9]/i

/*this above code is inserted before the declaration of formpanel*/

My real problem is to understand the syntax just before the written test function:

could someone please explain what this symbols means?

[0-9] = validate numbers from 0 to 9 (I think!)
$ = ?
/^ = ?
/i = ?

and if it is not asking too much to see also an example that works for my problem?

Thank you in advance

8 Apr 2011, 2:56 AM
I know little about RegEx but you can achieve what you want by using Ext.form.NumberField (http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.NumberField) and specifying allowDecimals: false and allowNegative: false in the config.

12 Mar 2012, 4:56 AM
Thank you man easy and logical way you suggested