Created
February 19, 2015 23:16
-
-
Save leocaseiro/1f6ac244c353cce02d04 to your computer and use it in GitHub Desktop.
RegEx Currency PHP $1,000,000.00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check if value is currency $value | |
* | |
* Pass on: | |
* 1,000,000.00 | |
* 10,000.00 | |
* 1,000.00 | |
* 100.00 | |
* 10.00 | |
* 1.00 | |
* 0.50 | |
* | |
* @param float $value | |
* @return bool | |
*/ | |
function validate_currency( $value ) { | |
return preg_match("/^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$/", $value ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment