The Requirement
The phone number from customer web site is free string. It can take the following forms:
- +1 (219) 555-8888
- +1 219-555-8888
- (219) 555 8888
- 219 555 8888
- 219 555-8888
- 219-555-8888
- -1-219-555-8888
There could be other form.
We need to use dataweave 2.0 to extract 10 digits of the phone number to: 2195558888.
Solution
%dw 2.0
output application/json
---
{
mobile: (payload.mobilePhone replace /([^0-9.]+)/ with(""))[-10 to -1]
}
Take Aways
- dataweave built in function replace / / with ()
- substring [-10 to -1] take last 10 digits