Here is my javascript function which replaces "yyyy" of a date format with "yy" and replaces "yy" with "y" example
validateDateFormat("dd/mm/yyyy") gives "dd/mm/yy"
validateDateFormat("dd/mm/yy") gives "dd/mm/y"
Here is my js function
function validateDateFormat(format) {
var index = format.indexOf("yyyy");
if(index <0 )
{ var index = format.indexOf("yy");
if(index <0 )
return format;
else
return format = format.substring(0, index) + format.substring(index+1);
}
else
return format = format.substring(0, index) + format.substring(index+2);
}
Am trying to re-write the function with switch or make it recursive, is it doable?
return str.replace(/yy/g, 'y');: jsfiddle.net/mQQdx. There may be a few edge cases...