0

I am using a acript to control the input field of my page where it can enters numbers only in telephone field. Can anyone help me on how to modify the code to allow a symbol '+' ?

<script>
function zz(txt)
{
	var txt1 = txt.value.replace(/[A-z]/g, "");
	document.getElementById('aa').value = txt1;
}
</script>

<input type="text" id="aa">
3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

Note that you can still type 033+2323 in the field:

<script type="text/javascript">
function zz(txt){
  var txt1 = txt.value.replace(/[^0-9\+]/g, "");
  document.getElementById('aa').value = txt1;
}
</script>

<input name="phone" type="text" id="aa" onblur="zz(this)" />
0

this will alert user to enter proper string which may or may not start with +

function zz(txt)
{

   isPhone     = /^[+]?\d+$/;

   if (!isPhone.test(txt))
   {
    alert('Invalid phone number');
    document.getElementById('aa').focus();
    return false;
   }
   return true
}

Edited by urtrivedi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.