Check for decimal points

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Check for decimal points

Post by aceconcepts »

Hi,

How would i check to see if any decimal points exist in a 'posted' field value?

i.e.

98.0 = Bad

90.8 = Bad

90 = Good
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Thanks for the reply.

I was hoping to output an error message if a decimal value was found.

Basically I only want users to be able to enter a 3 digit number into a form field and prevent any other values being input i.e. only numbers like ("455" or "635") NOT "54.0".

Hope this makes sense.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Compare the result from intval() with the original.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Ahhh what a good idea.

Thanks.
Post Reply