Format mobile number to this format "(845) 963-2545" #mobileFormat

 

// format phone number into foreign format
default no:8459632545 format to = (845) 963-2545
// if mobile values is = 8459632545
export const numberFormat = (value=> {
    if (value && value !== "") {
        let mobile = value.trim()
        const first = mobile.substr(03)
        const second = mobile.substr(33)
        const last = mobile.substr(64)
        const number = (`(${first}${second}-${last}`)
        return number
    } else {
        return ""
    }
}
expected output is = (845) 963-2545

Comments