jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers
https://intl-tel-input.com
MIT License
7.38k stars 1.93k forks source link

Question about strictMode #1609

Closed udit-001 closed 2 months ago

udit-001 commented 2 months ago

Plugin version

v22.0.2

Question about Strict Mode

When utilizing the strict mode in this plugin, my intention is to restrict users to input only specific types of numbers, particularly mobile numbers in the context of my use case. Since the placeholderNumberType parameter allows us to specify the numberType which is used for formatting the number displayed, I'm wondering if it's also feasible to implement validations within the strict mode for a specific number type, such as mobile numbers exclusively.

When attempting to input numbers longer than the standard length of mobile numbers in India, the plugin still permits the entry of digits exceeding ten characters. However, Indian mobile numbers typically adhere to a fixed length of ten digits.

Initialisation options

{
    initialCountry: "auto",
    strictMode: true,
    onlyCountries: ["id", "in", "bd"],
    separateDialCode: true,
    useFullscreenPopup: true,
    autoPlaceholder: "aggressive",
}
jackocnr commented 2 months ago

I'm wondering if it's also feasible to implement validations within the strict mode for a specific number type, such as mobile numbers exclusively.

Unfortunately, it's not possible to prevent users entering digits for other types of numbers, but...

When attempting to input numbers longer than the standard length of mobile numbers in India, the plugin still permits the entry of digits exceeding ten characters

If you update to v23.0.1, this should be fixed.

udit-001 commented 2 months ago

Thanks for the quick fix, this resolved the issue.

I have a follow-up question regarding strict mode. Since strict mode doesn't display error messages to the user, is there a method for me to tap into a validation failed event when using strict mode? This would allow me to show error messages to the user and make cosmetic adjustments to the input.

jackocnr commented 2 months ago

is there a method for me to tap into a validation failed event when using strict mode?

Do you mean you want a way to respond each time the user's key press gets rejected? If so, can you describe more how you would respond to this situation, as if the user is typing fast, there could be like 5 of these per second...