Jump to content

Replace text on input


wmguk

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.