?
Solved

Validating amount field in PHP

Posted on 2007-07-31
2
Medium Priority
?
169 Views
Last Modified: 2007-07-31
How would I validate a dollar amount in PHP?

For example, I want the text box to only take numbers. After a decimal point, I only want the textbox to take in 2 digits. So, these will be an invalid entries

$1234.5346346
A234.33
123.$A
$123.33

Note that there is no limit to the left of the decimal point. For example, a person could enter in 12334523542364.34 if he wanted to and it would still be valid.

THANKS!

FG
0
Comment
Question by:freezegravity
2 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 total points
ID: 19603904
<?

$string = "32312.23";


if(preg_match("/^\d+\.\d{2}$/",$string,$match)){

      print "SUCCESS";

}else{

      print "INVALID INPUT";
}

?>
0
 

Author Comment

by:freezegravity
ID: 19604255
Clean and effective!

THANKS A TON!

FG!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question