PDA

View Full Version : VType for Positive Numbers?



shaoen01
13 Jan 2012, 9:29 PM
Hi All,

I have a field that requires some validation. It can't be blank and it has to be a positive number. I have used vtype for url, email, etc. Anyone know how i can make my own vtype to ensure only positive and non-blank numerical values (decimals accepted) are entered? So i should only accept numbers 1 and above.

Any help on how to make my own custom simple vtype is very much appreciated!

Currently, this is my code below for non-Negative and non-blank in the editor grid (row editor plugin) i'm using.



{
xtype: 'numbercolumn',
text: "Amount",
dataIndex: 'paymentamount',
id: 'paymentamount',
width: 100,
hidden: false,
sortable: true,
renderer : 'usMoney',
field: {
xtype: 'numberfield',
allowBlank: false,
allowNegative: false
}

}

slemmon
13 Jan 2012, 11:56 PM
The top of this page has an example of making custom vtypes:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.VTypes

a (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.VTypes)nd you can use this regex
^\.?\d+$

A helpful resource you might refer to (my favorite for regex testing) is:
http://gskinner.com/RegExr/

shaoen01
14 Jan 2012, 2:53 AM
The top of this page has an example of making custom vtypes:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.VTypes

a (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.form.field.VTypes)nd you can use this regex
^\.?\d+$

A helpful resource you might refer to (my favorite for regex testing) is:
http://gskinner.com/RegExr/

Thanks, i managed to do it! I am just wondering what should i put for the mask? What does it do?

slemmon
14 Jan 2012, 10:41 AM
The mask would be a regex of characters that will be allowed by the field with the vtype. Any characters that do not fit the regex cannot be typed into the field. So, for your field you might use a mask of
/[\.\d]/g

to enforce the entering of only numeric characters and "."

shaoen01
18 Jan 2012, 4:03 AM
The mask would be a regex of characters that will be allowed by the field with the vtype. Any characters that do not fit the regex cannot be typed into the field. So, for your field you might use a mask of
/[\.\d]/g

to enforce the entering of only numeric characters and "."

Thanks slemmon. I will try it out shortly and give a shout out if i have any problems!