English 中文(简体)
如何用javascript掩盖超文本输入?
原标题:How can I mask an HTML input using javascript?
  • 时间:2011-10-05 18:18:09
  •  标签:
  • javascript

我怎么能够用javascript在超文本控制上掩盖美国电话。

我谨以以下形式提出意见:

[(111)111-1111]

这里,我是:

mask(str, textbox, loc, delim) {
    var locs = loc.split( , );
    for (var i = 0; i <= locs.length; i++) {
        for (var k = 0; k <= str.length; k++)
        {
            if (k == locs[i]) {
                if (str.substring(k, k + 1) != delim) {
                    str = str.substring(0,k) + delim + str.substring(k,str.length)
                }
             }
         }
     }
     textbox.value = str
} 
最佳回答

处理有保证格式的电话号码投入的三种共同方式:

页: 1 接受所有数字输入

用户人数模糊但在美国仍生活在美国的可能性比以往任何时候都要高。 接受各种数字投入会减轻人们的关切,因为只有给你数量不足或错误的数字,数字才会无用。

2。

许多金融软件就是这样。 具体地说,这并不肯定为什么会非常频繁。 一项建议是,如果 cur在案文箱上排出最大限额,则将 cur放在下一个盒子后面。 此外,这种保障将获得你所期望的任何形式,因为你只能把由此产生的员额变量加在一起。

传真例:

<input id="phonePart1" maxlength="3" name="phonePart1"/>
<input id="phonePart2" maxlength="3" name="phonePart2"/>
<input id="phonePart3" maxlength="4" name="phonePart3"/>

和稍微少的 j子,以你的形式将三者合并起来:

var phonePart1 = parseInt($("#phonePart1").val(), 10);
var phonePart2 = parseInt($("#phonePart2").val(), 10);
var phonePart3 = parseInt($("#phonePart3").val(), 10);
var phone = "(";

if (isNaN(phonePart1)||isNaN(phonePart2)||isNan(phonePart3)) {

    // Incorrect format

} else { 

    phone = phone + phonePart1 + ")" + phonePart2 + "-" + phonePart3;

}

3。 定期表达与编号格式

You can use a combination of regular expressions to match multiple numbers, or explicitly the one you are asking about. This is probably the technique you re looking for. This is the regular expression:

/([0-9]{3})[0-9]{3}-[0-9]{4}/

You d use it like this:

if (yourphonevariable.match(/([0-9]{3})[0-9]{3}-[0-9]{4}/))
{
    // it s valid
}

<>4>。 如果你想用面罩来编排案文本身。

考虑。 用户@John Gietzen建议我不要担任这一职务,因此认为可以免费为他提供库多。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.