Fossi in te farei tutto lato server, utilizzando qualche regex.