GWT电话号码掩盖

Mat*_* B. 4 java gwt phone-number

有谁知道如何创建将执行电话号码格式屏蔽的字段,如下所示(___) ___-____:http:
//www.smartclient.com/smartgwt/showcase/#form_masking

gat*_*kin 8

更好的办法是让他们想要的用户类型:"789-555-1234"或"(789)555-1234"或"7895551234",然后在字段失去焦点决定他们是否键入的内容可以是一个电话数.如果是这样,您可以将其重新格式化为"(789)555-1234".有关如何使用正则表达式执行此类操作的几个相关问题; 只是要确保你的正则表达式接受你正在改变用户输入的格式,否则编辑真的很烦人.

例如,查看在Microsoft标准页面设置对话框的左边距字段中键入".5"时会发生什么:当您选中它时,将其更改为"0.5".

更新:这是GWT中的示例代码来说明.为了这个例子,假设有一个名为"phoneContainer"的元素来放置文本框.GWT没有给你完整的java.util.regex包,但它足以做到这一点:

private void reformatPhone(TextBox phoneField) {
    String text = phoneField.getText();
    text = text.replaceAll("\\D+", "");
    if (text.length() == 10) {
        phoneField.setText("(" + text.substring(0, 3) + ") " + text.substring(3, 6) + "-" + text.substring(6, 10));
    }
}


public void onModuleLoad() {
    final TextBox phoneField = new TextBox();

    RootPanel.get("phoneContainer").add(phoneField);
    phoneField.addBlurHandler(new BlurHandler(){
        public void onBlur(BlurEvent event) {
            reformatPhone(phoneField);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)