How can I change "flat 3 245a HILL road" to "Flat 3 245A Hill Road" in javascript? -
when enters street address single field on form, want convert street address title case. isn't quite title case letter comes directly after string of numbers should upper case.
as example want "flat 3 245a hill road" not "flat 3 245a hill road".
i know that:
var str = "flat 3 245 hill road"; str.split(" ").map(function(i){return i[0].touppercase() + i.substring(1).to lowercase()}).join(" "); will convert "flat 3 245a hill road" "flat 3 245a hill road".
but want convert "flat 3 245a hill road"?
another example
it should "18b hill crescent" not "18b hill crescent"
try
str.replace(/(\d+)([a-z]+)/, function(a) { return a.touppercase(); }) to handle 245a
Comments
Post a Comment