Cordova Contacts Plugin ContactFindOptions filter

339 Views Asked by At

I have some troubles with the contact plugin for cordova, i want to add a filter on contacts with valid phone numbers, how can i add a regexp? javascript regex doesn't seem to work, i need something like [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!');
}

Thanks in advance!

1

There are 1 best solutions below

0
On BEST ANSWER

I realized that he latest update include now an option to fetch only the contacts with a phone number. The option id false by default.

options.hasPhoneNumber = true;