I have this code:
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
var src = document.getElementById("one"),
dst = document.getElementById("two");
src.addEventListener('input', function() {
dst.value = src.value.replace(/\D/g,'');
});
};
</script>
</head>
<body>
<input type="text" id="one" name="one">
<input type="text" id="two" name="two">
</body>
</html>
This will remove everything that isn't a digit from one
and insert in two
.
But I want to keep only a string of five digits side by side.
Means, if one
is:
test 1 test 1234 test
; no output
test 1 12345 test
; output 12345
test 123456 test 12 test
; no output
12394 test
; output 12394
84725
; output 84725
Does anybody know how to change the REGEX to reach this?