• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Preg_match dd-mm-yyyy

#1
I have this code below which checks the date format dd/mm/yyyy

But i need it to check it like dd-mm-yyyy

Question: What is the correct preg_match that can check this dd-mm-yyyy not dd/mm/yyyy

PHP Code:
if ($this->input->post('dob')) 
{

if (
!== preg_match('/(0[1-9]|1[0-9]|2[0-9]|3(0|1))\/(0[1-9]|1[0-2])\/\d{4}/'$this->input->post('dob'))) 
{
$this->error['dob'] = 'Date needs to have a valid date format - dd-mm-yyyy';
}


There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
Try something like that (or use php checkdate method)

Code:
preg_match('/^(\d{2})-(\d{2})-(\d{4})$/', $this->input->post('dob'));

Reply

#3
(05-19-2017, 03:23 AM)Rufnex Wrote: Try something like that (or use php checkdate method)

Code:
preg_match('/^(\d{2})-(\d{2})-(\d{4})$/', $this->input->post('dob'));

Thanks again for great help works perfect
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.