user3532863 user3532863 - 7 months ago 6
Javascript Question

How to replace date pattern in javascript string

How to remove a date patterns in a JavaScript string like below?
from "Mobile Phone 1/15/06" to "Mobile Phone"

var str ="Mobile Phone 1/15/06";

ccf ccf
Answer

You could use regex to match and replace the date pattern:

var str ="Mobile Phone 1/15/06";
var result = str.replace(/\s+\d{1,2}\/\d{2}\/\d{2}/g, '');
document.write(result);