yii rules numerical float

04Dec11

if you want to validate a float number you can use this:

    public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(

array(‘price’, ‘numerical’, ‘integerOnly’=>FALSE,’numberPattern’=>’/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/’,'message’=>’erroreeeeee’),

);
}

Example: 19.32

 



One Response to “yii rules numerical float”

  1. You might want to consider extending CNumberValidator to do this. That way it is reusable. We extended the CNumberValidator to make our own validator for Zurmo (http://www.zurmo.org), an open source crm application.


Lasă un răspuns

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Schimbă )

Twitter picture

You are commenting using your Twitter account. Log Out / Schimbă )

Facebook photo

You are commenting using your Facebook account. Log Out / Schimbă )

Connecting to %s


Follow

Get every new post delivered to your Inbox.