Sanitizing Numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying to sanitize some numeric data that's coming to us from
another system which I have no control over where all fields are
character fields with no formatting from the end user so data is a
mishmash of clean and mixed types of dirty.

I know I can use intval and floatval to sanitize if the numeric data
is at the front of the string but what about when it's not?

For example, Jersey Number = #45 or Dues = $1,234.56....

I see in the comments at php.net for floatval a lot of very complex
solutions... am I missing something about the following that wouldn't
cover me?

<?php $output = floatval(ereg_replace("[^-0-9\.]","",$input)); ?>

I'm willing to assuming only US formatted numbers... and knowing that
if they put in 45/46 for jersey it would come out 4546 (but I might
put in additional code for that specific case on that specific
field...). I'm also looking for something that I can generically apply
to any numeric field.

Thanks for your collective guidance.

Matt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux