CORT0619 Posted November 15, 2011 Share Posted November 15, 2011 Does anyone know how I can validate US currency using php that is entered into a textbox? The textbox is setup as a decimal in mysql and i'm trying to make sure only decimals are entered so when php calculates the values entered I don't receive errors. Quote Link to comment https://forums.phpfreaks.com/topic/251207-validating-currency-in-text-field/ Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 <?php $value = 32.50; $isValid = filter_var($value, FILTER_VALIDATE_FLOAT); //RETURNS TRUE ON SUCCESSFULL VALIDATION, FALSE FOR UNSUCCESSFUL //THIS WILL EVALUATE FOR A DECIMAL (FLOAT), THERE ARE ADDITIONAL FLAG IS YOU WANT TO VET OUT TO THE THOUSANDS PLACE ?> Read up on filter_var() and its constants here: http://us3.php.net/manual/en/filter.filters.php filter_var() is still invoking the PCRE engine; so your still getting the benefit of REGEX, without all the guess work. Quote Link to comment https://forums.phpfreaks.com/topic/251207-validating-currency-in-text-field/#findComment-1288436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.