Skip to content

Instantly share code, notes, and snippets.

@leocaseiro
Created February 19, 2015 23:16
Show Gist options
  • Save leocaseiro/1f6ac244c353cce02d04 to your computer and use it in GitHub Desktop.
Save leocaseiro/1f6ac244c353cce02d04 to your computer and use it in GitHub Desktop.
RegEx Currency PHP $1,000,000.00
<?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