Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
search(text) {
const phoneNumberRegex = /\b[\+]?[(]?[0-9]{2,6}[)]?[-\s\.]?[-\s\/\.0-9]{3,15}\b/m;
const emailAddressRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;
if (text === "" || text === null) {
this.loadContacts();
} else if (phoneNumberRegex.test(text)) {
Contacts.getContactsByPhoneNumber(text, (err, contacts) => {
this.setState({ contacts });
});
} else if (emailAddressRegex.test(text)) {
Contacts.getContactsByEmailAddress(text, (err, contacts) => {
this.setState({ contacts });
});
} else {
Contacts.getContactsMatchingString(text, (err, contacts) => {
this.setState({ contacts });
});
}
}
return new Promise((resolve, reject) => {
Contacts.getContactsMatchingString(searchString, (err, contacts) => {
if (err) {
reject(err)
return
}
resolve(contacts)
})
})
}