PHP Verify a Dollar Amount

///PHP Verify a Dollar Amount

PHP Verify a Dollar Amount

Just a simple function to see if an input numeric value is actually a US Dollar (USD) format\r\nExample:\r\nTwo Dollar Amounts provided to the script.. 1502.38 and 10O.00\r\n\r\nGood: 1,502.38\r\nBad: 10O.00 came back false. \r\n\r\n
\r\nfunction verifyMoney($what){\r\n   if (preg_match('#^[0-9]+(\.[0-9]{0,2})?$#', $what)){\r\n     $monkey = number_format($what, 2);\r\n     return $monkey;\r\n   }else{ return FALSE; }\r\n}\r\n\r\n$goodmoney = "1502.38";\r\n$badmoney = "10O.00";\r\nif(verifyMoney($goodmoney) !== FALSE) {echo "Good: ".verifyMoney($goodmoney);}else{echo "The Dollar amount you have entered is not valid";}\r\nif(verifyMoney($badmoney) == FALSE) {echo "Bad: ".$badmoney." came back false.";}else{echo "The Dollar amount you have entered is valid";}\r\n
By | 2014-01-05T10:23:29+00:00 March 8th, 2012|Code, PHP|0 Comments

About the Author:

Not much to know about me, I'm a 35+ year old coder, geek, gamer..

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: