₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,301 members, 8,425,946 topics. Date: Saturday, 13 June 2026 at 11:35 AM

Toggle theme

Preg_match Problem In Php - Webmasters - Nairaland

Nairaland ForumScience/TechnologyWebmastersPreg_match Problem In Php (652 Views)

1 Reply

Preg_match Problem In Php by ayodeleolu2014(op): 1:51am On Jul 26, 2014
I'm currently working on a small web application called expenses whereby can save your expenses to a mysql db via php array.

Here is how it works.

In the first page, you'll have to enter the number of items that you want to save their expenses to the mysql db.

So, let's assume that you enter 3 as the number of items, you'll be redirected to another page whereby you'll be provided with textboxes where you'll enter the name of the items and their corresponding amounts and then click on save button to save it to the database.

So, how can i restrict the amount textboxes to accept only numeric characters and a dot in such a way that numeric character must start, then followed by a dot (which is optional) and it must also end with a numeric character.

e.g 100.8 , 250.4 , 250, 300.8 , 200.

This is my code


foreach ($amount as $digit)
{
if((!ctype_digit($digit)) || ($digit<1) || (!preg_match("/[\.]$/",$digit)))
{
echo " Only positive, numeric, non-zero digits and a dot are allowed for amount of item";
exit();
}
}

I'll be glad if you help me correct this because it's been up to 2 days now that I've been battling with this.

THANKS AND GOD BLESS!
1 Reply

How Can I Solve 404 Error Problem In A Wordpress SiteHow Do I Solve This Problem In Uploading My Joomla WebsiteWhat's The Difference Between "require Once" And "include" In Php?234

RolcevibezSecrets To Improve Your Page Rank-by Amelia JoeWeb Development Training At Affordable Price