Please tell me how to extract a phone number in the format +1118889977 from the body of a email into a variable?
Extract phone number from email body
Collapse
X
-
Hey
You can use formula match with a regular expression to extract such numbers from the email, below code:
PHP Code:// Use this to extract just one number from the body of the email $phone = string\match(body, '/\+\d{10,}/');
PHP Code:// Use this to extract an array of all numbers from the body of the email $phones = string\matchAll('{token1} +1118889222 {token2} bar', '/\+\d{10,}/');
Remember this regular expression will look for any number within the body that starts with (+) and has 10 digits.
I hope this helps Rabii
Web Dev -
Comment
-
stuck on the next step...
step 1. Extracting the phone number, thanks to rabii for the help!
PHP Code:$phone = string\match(body, '/\+\d{10,}/');
PHP Code:ifThenElse($phone, record\exists('Lead', 'phoneNumber=', $phone), false);
step 3. I need to update email entity -> related record Email with Lead (extract ID of found record)Comment
-
Hey
Not sure what the second step serves but i would just check the condition and update the email record (assuming this formula is for Email entity), see code below
PHP Code:ifThen( $phone && record\exists('Lead', 'phoneNumber=', $phone), // if condition is true $leadId = record\findOne('Lead', 'createdAt', 'desc', 'phoneNumber=', $phone); $leadName = record\attribute('Lead', $leadId, 'name'); // update the parent of the email with the found lead id record\update('Email', id, 'parentId', $leadId, 'parentName', $leadName); )
I hope this helpsRabii
Web DevComment
Comment