Jump to content

Recommended Posts

Not sure if this helps but you could do this

<?php
$data = '19.9.74, 19/9/74, 19/09/74, 19.09.74, 19.09.1974, 19/09/1974';
$data = preg_replace('/(\d{1,2}).(\d{1,2}).(19|20)?(\d{2})/i', '\1/\2/\3\4', $data);

echo $data; //19/9/74, 19/9/74, 19/09/74, 19/09/74, 19/09/1974, 19/09/1974
?>

 

EDIT: ooops just re-read.. i thought to had a ton of info and needed to reformat it..

 

for getting the input you could google JS calander theirs tons and it look fancy or have 2-3 drop downs

Had a quick play, regular expression would look something like:

 

^[\d]{2}[-\.:\|][\d]{2}[-\.:\|](19|20)[\d]{2}$

 

.. That would only match a string in format: DD MM YYYY with a delimiter between them of either: - : . |

 

However I do not know how you could use preg_replace() to replace the delimiter with / every time, perhaps somebody else has an idea??

 

Adam

however people put anything from 19.9.74, 19/9/74, 19/09/74, 19.09.74, 19.09.1974, 19/09/1974

 

One or two I didn't notice before but, he doesn't appear to be having problems with "15th December 2008".. A maxlength of 10 would also prevent them entering anything like that.

 

Give them a hint? For example:

 

Date of birth: [                              ] Eg. 19/9/1974

 

Would stop the masses entering it wrong, and should account for the odd one who uses a different delimiter!

 

Adam

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.