PDA

View Full Version : User can able to input only one '.' and '%'



amanind
11 Jul 2011, 5:12 AM
Hi

I want restrict user only able to input one '.' and '%' in the textfield.
like "22.1%" not "2.2.1%"
If he input second '.', value should revert back to original value

How to do this

Uberdude
11 Jul 2011, 5:44 AM
You could do this with a custom validator function, specified as the validator config option (or to be more reusable, with vtype) of a TextField. However, if the user is always expected to type a percent symbol, I wonder if it would be a better design to simply use a NumberField (which means you get the validation it is a valid number for free) and just stick a '%' in a label to the right.