使用正则表达式实时响应本机

时间:2018-08-03 14:36:34

标签: typescript react-native mask

我已经使用React-Native和TypeScript在我的公司上启动了一个项目,而我们在pt-br中的蒙版方面遇到了麻烦...我无法在npm代码中使用默认库,因为它不是灵活的代码,目前,我真的很想使用正则表达式转换状态并接收掩码,在这里,我们使用这样的掩码电话(41)9 9887-7665传递值(41998877665)并返回带有掩码的代码,我是否尝试了太多代码js,但无法正常工作...

我真的只想知道如何在react-native中使用正则表达式。

  _addMaskPhoneBr(phone: any){  //this is my function to add mask into my screen
    phone = phone.replace(/^[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-/\s.]?[0-9]{4}$/); //mask have i try to apply, i know this will not return a spected result, but after i can use i'll fixit to a mask pt br

    this.setState({ phone: phone }); // set state to reload value into textInput {stateVariable: setValu}
 }

用户输入电话的组件...

<View style={viewEditStyle}>
 <TextField 
  label={I18n.t("proposalDetail.phone")} 
  value={this.state.phone} //this reload value from state
  keyboardType="numeric"
  onChangeText={value => this._addMaskPhoneBr(value)} // this set function a value to add mask
  maxLength={16}
 />

Pic from Console.log returns

感谢所有帮助!

1 个答案:

答案 0 :(得分:0)

我使用以下代码修复了吗:

$( document ).ready(function() {

    $('#example').DataTable( {
        "columnDefs": [ {
    "targets": 3,
    "createdCell": function (td, cellData, rowData, row, col) {
      if (( cellData > 3 ) && ( cellData < 10 )){
        $(td).css('color', 'green')
      }
      else
           if (( cellData > 11 ) && ( cellData < 45 )){
        $(td).css('color', 'orange')
      }
      else
           if (( cellData > 45 ) && ( cellData < 100 )){
        $(td).css('color', 'red')
      }
    }
  } ],

language: {
        searchPlaceholder: "Search records"
    },
 "ajax": {
             "type"   : "POST",
            "url": "1.json",
             "dataSrc": function (json) {
      var return_data = new Array();
      for(var i=0;i< json.length; i++){

        return_data.push({

         'name': json[i].name,
          'stargazerscount'  : '<span onclick="f()">'+json[i].stargazerscount+'</span>',
           'forkscount'  : json[i].forkscount,
          'description' : json[i].description,

        })

      }
      return return_data;
             }
    },

        "columns": [
            { "data": "name" },
            { "data": "stargazerscount" },
            { "data": "forkscount" },
            { "data": "description" }

        ]

}); 
});

}