Example :(080) 235-4354
function PhoneNumberValidation(e) {
var keynum;
var keychar;
// For Internet Explorer
if (window.event) {
keynum = e.keyCode;
}
// For Netscape/Firefox/Opera
else if (e.which) {
keynum = e.which;
}
keychar = String.fromCharCode(keynum)
var r = new RegExp("[0-9]", "g");
if (keychar.match(r) == null) {
return false;
}
else {
var getValue = document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').value;
var s = getValue.length;
if (s == 3) {
document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').value = '(' + document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').value + ') ';
}
if (s == 9) {
document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').value = document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').value + '-';
}
return true;
}
}
<td>
<asp:TextBox ID="txtPhone" runat="server" MaxLength="14" onkeypress="return PhoneNumberValidation(event)"></asp:TextBox>
</td>
No comments:
Post a Comment