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">

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)" />

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
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.