Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,194,263 members, 7,954,025 topics. Date: Friday, 20 September 2024 at 11:04 AM

Preg_match Problem In Php - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Preg_match Problem In Php (609 Views)

How Can I Solve 404 Error Problem In A Wordpress Site / How Do I Solve This Problem In Uploading My Joomla Website / What's The Difference Between "require Once" And "include" In Php? (2) (3) (4)

(1) (Reply)

Preg_match Problem In Php by ayodeleolu2014: 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)

See How To Make N300,000 Daily Online - No Work Needed / Abeg review this blog / Free Php/mysql Web Hosting

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.