Using JavaScript adding '-' in number

windows

Guest
Hi,
I want to add "-" char in 15 digit number after each 3 char.
like 234875987345236 when user enter this number in text box then it looks like 234-875-987-345-236
Using Java Script I am adding "-" but it fails when I paste number in textbox.

function AddDash(elem)
{
var min = elem.value;
if(min.length == 3 || min.length == 7 || min.length == 11 || min.length == 15)
{ concatMin(elem);}
}
function concatMin(elem)
{
var min = elem.value;
min += '-';
elem.value = '';
elem.value += min ;
}
</script>
<asp:TextBox id="TextBox1" runat="server" onkeydown="AddDash(this)" MaxLength="19" ></asp:TextBox>

Can any one help me out from this.
Thanks in Advance
SukhThis question is really not an asp.net question at all, it is a javascript question, so you might getter a better answer in that forum. Would you mind if I moved the thread there?

Also, you should run a backend asp.net script to check that string to make sure the dashes are in it on post because roughly 10% of the internet does not support javascript and you do not want 10% of your data base records to be flawed.
 
Back
Top