Yii Framework Forum: How To Validate Number In Model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Validate Number In Model with decimals Rate Topic: -----

#1 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 28 February 2013 - 07:31 PM

I would like to validate my numbers in my form with decimal places.

a user could enter a value for the first one (concentration)

can be max of 10 numbers . 8 numbers
1,000,000,000.12345678

the second is 3 numbers . 2 numbers
ie 100.25


The problem is that it can have a decimal or it doesn't have to for whole numbers i.e 100 and it is also requiring a 0 after. so 100.0.

This validates properly except for a whole numbers WITHOUT a decimal it is requiring a decimal due to how I set it up.

How could I validate it to have or not have a decimal?

array('concentration', 'match', 'pattern'=>'/^[0-9]{0,10}(\.[0-9]{0,8})/'),
array('temperature', 'match', 'pattern'=>'/^[0-9]{0,3}(\.[0-9]{0,2})/'),


Thanks for your help in advance!
0

#2 User is offline   mirunho 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 19-December 12
  • Location:Gdansk, Poland

Posted 01 March 2013 - 02:35 AM

In regular expressions You can use ? for optional instance of some symbol or letter, so maybe it will help
0

#3 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 01 March 2013 - 03:39 AM

This will help you

http://www.yiiframew...s-and-i18n/#hh1
0

#4 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 01 March 2013 - 10:07 AM

View PostBalu, on 01 March 2013 - 03:39 AM, said:



Thanks, However, I already have the number formatting after it is pulled from the db. I just wanted to know a way to validate it with or with out a decimal.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users