Quantcast
Channel: Reformat string containing uk postcode using regex - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Reformat string containing uk postcode using regex

$
0
0

How can I format a string using Javascript to match a regex?

I am using UK postcodes which could match any of the following

N1 3LDEC1A 3ADGU34 8RR

I have the following regex which validates a string correctly, but I am unsure how to use the regex as a mask to format EC1A3AD to EC1A 3AD / GU348RR to GU34 8RR / N13LD to N1 3LD.

My regex is /^[A-Za-z]{1,2}[0-9A-Za-z]{1,2}[ ]?[0-9]{0,1}[A-Za-z]{2}$/

Thank you


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>