0

I use the following code to create the textbox for enter the phone number in run Time .How to add hyphen(-) in between the phone Numbers.For example If I type 1234567 the entry should show like this 123-45-67 how to do this? how to do this in JQuery?

<input id="abcd" type="text" value="" style="width:220px">
TRR
  • 1,637
  • 2
  • 26
  • 43
user
  • 189
  • 3
  • 8
  • 18
  • you can use this JavaScript plugin http://digitalbush.com/projects/masked-input-plugin/ – Ram Jun 11 '12 at 06:28

2 Answers2

1

You have to use JavaScript for this. I think this is a good starting point... Bottom line is, though, you will have to do some scripting for this. (Basically, when the field is changed, check if it's the right amount of #s, and add a hyphen if necessary.)

I would recommend jQuery for this; a quick Google turns up some useful results.

Keep in mind that phone numbers from different parts of the world will be hyphenated differently. The USA, for example, uses +x-xxx-xxx-xxxx, while Argentina uses +xx-xx-xxx-xxxx. Some european countries use +xxx-xxxx-xxxx.

Cat
  • 66,919
  • 24
  • 133
  • 141
  • 1
    To add to Soxxeh’s third paragraph, the international (ITU) convention on writing telephone numbers uses spaces for grouping, not hyphens. The reasonable approach is to let the user enter the number as he likes, let him see it that way, and interpret it liberally, allowing but not requiring spaces, hyphens, and parentheses. – Jukka K. Korpela Jun 11 '12 at 06:37
0

you can do it with the help of Mask. Check this link on how to Mask the textbox data as desired.

TRR
  • 1,637
  • 2
  • 26
  • 43