Based on your current and previous posts, I'm guessing, you want the textbox to show only the phone format that matches the regular expression. I don't think the replace approach will work because it will replace the valid phone with empty string. The below code will store the valid input into a temporary variable if the input matches the regular expression. if not match, restore the textbox value with the temporary value.
Here is an example.
<input type="text" id='txtPhone'>
var tempPhone = '';
$("#txtPhone").keyup(function (e) {
if($(this).val().match(/^\+?\d{0,}$/))
{
tempPhone = $(this).val();
$(this).val( tempPhone);
}
else {
$(this).val( tempPhone);
}
});
$('#txtPhone').on('paste', function () {
tempPhone = '';
});
Example:
CP_phone_number - JSFiddle[
^]