I want to insert a slash after every two characters, but just for the first two instances. The following regex inserts after every occurrence. Does anyone know how to limit it to two occurrences? The amount will be entered by the user through an input element. So if a user entered 30032017
it would be something like the following.
function insertSlash(val) {
return val.match(new RegExp('.{1,2}', 'g')).join("/");
}
insertSlash(input);
so for the first character the user would enter 3
. On the next input it will be 0
. this should then insert a slash.
this should then return 30/03/2017
.