I’m trying to use imask.js for phone validating on subscribe form.
I currently have this simple code :
var phoneMask = IMask(
document.getElementById('number_phone'), {
mask: '+{33}000000000'
});
I want to disable the capacity of put a 0 just after the {33} to have this kind of number at the end of the subscription : +33666666666. But allow to put a 0 after the first number.
I’ve try some Regex but still not working 🙁
3
Answers
Instead of using a single mask for the whole phone number, we break it into three parts:
What the masks does:
+33
is always present.0
. We use a custom definition to only allow digits from1
to9
.0
).The mask will prevent the user from entering a
0
immediately after the+33
country code but will allow entering a0
after the first digit.You can achieve the desired behavior by using a regular expression in the mask option of imask.js. Here’s an updated code snippet that should work for you:
Examples above did not seem to work with
useIMask
react-hook. This one is a bit simpler and works with the hook also.