Skip to main content
edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Funtion Function to validate date format

Tweeted twitter.com/#!/StackCodeReview/status/530821315519713280
deleted 23 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Javascript funtion Funtion to validate date format

I have below javascript funtionthis JavaScript function which checks if the format has 'yyyy' and replaces 'yy' with 'y'

below is my function:

function validateDateFormat(format) { 
    if(format.indexOf("yyyy") != -1)
     return format.replace(/yy/g, 'y'); 
     else return format;
}

I feel like it can be simplified further, can. Can someone help me to refactor/optimize it?

Javascript funtion to validate date format

I have below javascript funtion which checks if the format has 'yyyy' and replaces 'yy' with 'y'

below is my function

function validateDateFormat(format) { 
    if(format.indexOf("yyyy") != -1)
     return format.replace(/yy/g, 'y'); 
     else return format;
}

I feel like it can be simplified further, can someone help me to refactor/optimize it?

Funtion to validate date format

I have this JavaScript function which checks if the format has 'yyyy' and replaces 'yy' with 'y':

function validateDateFormat(format) { 
    if(format.indexOf("yyyy") != -1)
     return format.replace(/yy/g, 'y'); 
     else return format;
}

I feel like it can be simplified further. Can someone help me to refactor/optimize it?

Source Link
OTUser
  • 747
  • 3
  • 8
  • 17

Javascript funtion to validate date format

I have below javascript funtion which checks if the format has 'yyyy' and replaces 'yy' with 'y'

below is my function

function validateDateFormat(format) { 
    if(format.indexOf("yyyy") != -1)
     return format.replace(/yy/g, 'y'); 
     else return format;
}

I feel like it can be simplified further, can someone help me to refactor/optimize it?