Skip to content

Commit

Permalink
fix: Fixed phone number validate (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrosroc committed Dec 28, 2022
1 parent c2a3406 commit 5405cdc
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/util/functions.js
Expand Up @@ -28,15 +28,21 @@ export function contactToArray(number, isGroup) {
let localArr = [];
if (Array.isArray(number)) {
for (let contact of number) {
contact = contact.split('@')[0];
while (! /^[a-zA-Z0-9]+$/.test(contact))
{
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g,'');
}
if (contact !== '')
if (isGroup) localArr.push(`${contact}@g.us`);
else localArr.push(`${contact}@c.us`);
}
} else {
let arrContacts = number.split(/\s*[,;]\s*/g);
for (let contact of arrContacts) {
contact = contact.split('@')[0];
while (! /^[a-zA-Z0-9]+$/.test(contact))
{
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g,'');
}
if (contact !== '')
if (isGroup) localArr.push(`${contact}@g.us`);
else localArr.push(`${contact}@c.us`);
Expand All @@ -50,13 +56,19 @@ export function groupToArray(group) {
let localArr = [];
if (Array.isArray(group)) {
for (let contact of group) {
contact = contact.split('@')[0];
while (! /^[a-zA-Z0-9]+$/.test(contact))
{
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g,'');
}
if (contact !== '') localArr.push(`${contact}@g.us`);
}
} else {
let arrContacts = group.split(/\s*[,;]\s*/g);
for (let contact of arrContacts) {
contact = contact.split('@')[0];
while (! /^[a-zA-Z0-9]+$/.test(contact))
{
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g,'');
}
if (contact !== '') localArr.push(`${contact}@g.us`);
}
}
Expand Down

0 comments on commit 5405cdc

Please sign in to comment.