libphonenumber-js icon indicating copy to clipboard operation
libphonenumber-js copied to clipboard

AsYouType doesn't work for "FR" and other countries. Only works for "US".

Open iamsamiadnan opened this issue 1 year ago • 4 comments

//AsYouType doesn't work for "FR" and other countries. Only works for "US". // please fix it asap let format = new AsYouType("FR").input(e.target.value);

iamsamiadnan avatar May 03 '24 15:05 iamsamiadnan

having same issue for Singapore numbers new AsYouType('SG').input('80901234') it has issue when the number input starts with '809' for some reason

mechastriker3 avatar Sep 10 '24 15:09 mechastriker3

Perhaps that's Google's issue. See https://github.com/catamphetamine/libphonenumber-js?tab=readme-ov-file#bug-reporting

catamphetamine avatar Sep 10 '24 15:09 catamphetamine

It's crazy, having same issue here, can you help reach out. @catamphetamine

Also, is there a quick alternative we can use?

michael-nwuju avatar Sep 11 '24 20:09 michael-nwuju

Hi @iamsamiadnan,

I looked into this and here’s what I found.

  • Singapore (from the comment): As of current metadata, it formats correctly.

    new AsYouType('SG').input('80901234')
    // → "8090 1234" ✅
    

    You can also verify this on the demo page (it uses “max” metadata).

  • France (from the issue description): AsYouType doesn’t add digits. If a user types without the national trunk prefix 0, formatting won’t engage:

    new AsYouType('FR').input('612345678')
    // → "612345678"  // no formatting (missing 0)
    new AsYouType('FR').input('0612345678')
    // → "06 12 34 56 78" ✅
    

    If you want a proper national render after input (regardless of whether 0 was typed), get the final number and format it:

    const f = new AsYouType('FR')
    f.input(e.target.value)
    const formatted = f.getNumber()?.formatNational()
    // e.g. "06 12 34 56 78"
    

Also, ensure you’re on the latest version/metadata so you get the most recent formatting behavior.

Refs:

  • Demo (shows SG 80901234 → “8090 1234”): https://catamphetamine.gitlab.io/libphonenumber-js/?parseCountry=US&parseValue=213-373-4253&asYouTypeCountry=SG&asYouTypeValue=80901234&findNumbers

groovypark avatar Sep 14 '25 05:09 groovypark