【发布时间】:2015-06-11 10:35:08
【问题描述】:
我在使用 cordova 的联系人插件时遇到了一些问题,我想为具有有效电话号码的联系人添加过滤器,如何添加正则表达式? javascript regex 似乎不起作用,我需要类似 [0-9]
function onDeviceReady() {
// find all contacts with 'a phone number' in any name field
var options = new ContactFindOptions();
options.filter = '6'; // retriev all phones with a 6
//options.filter = /[0-9]/ doesn't work
var fields = ["phoneNumbers"];
options.multiple = true;
navigator.contacts.find(fields, onSuccess, onError, options);
}
// onSuccess: Get a snapshot of the current contacts
function onSuccess(contacts) {
alert(contacts.length);
alert(JSON.stringify(contacts));
}
// onError: Failed to get the contacts
function onError(contactError) {
alert('onError!');
}
提前致谢!
【问题讨论】:
-
我是否正确假设它是(注释掉的)行,
options.filter = /[0-9]/,您没有开始工作,并且您想要关于如何仅过滤数字的建议?跨度> -
是的,注释行是行不通的。
标签: javascript regex cordova contacts