₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,063 members, 8,438,631 topics. Date: Friday, 03 July 2026 at 05:32 PM

Toggle theme

Preg_match Problem In Php - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPreg_match Problem In Php (724 Views)

1 Reply (Go Down)

Preg_match Problem In Php by ayodeleolu2014(op): 8:05pm On Jul 25, 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!
Re: Preg_match Problem In Php by ayodeleolu2014(op): 1:48am On Jul 26, 2014
Programmers in nairaland, please help.. dnt just view this thread!
Re: Preg_match Problem In Php by phpier:
.......... Try this , if(! preg_match( "/[\ .]+$/s" ,$digit)) ;
Re: Preg_match Problem In Php by phpier: 5:36am On Jul 26, 2014
..............
Re: Preg_match Problem In Php by Olyboy16(m): 8:54pm On Jul 26, 2014
Why preg_match ? If i'm to b precise you want the input to be a float number right? Then first check if d user has entered a valid positive numeric value with somfin lyk (is_numeric() !< 0 ) i hope u undastand d logic dia, and then type cast to float like this.. (float)$input;
shikena!
1 Reply

Solution To Tokenmismatchexception Problem In Laravel 5.1Simple Array Problem In PhpRunning Python Codes In Php234

Please I Need Someone That Can Help Set Up A Short Code SMS Service For An EventDoes Your Hotel Suffer Data Manipulations?Have Anyone Attended Moatacademy For Programming Lessons