vue-tel-input icon indicating copy to clipboard operation
vue-tel-input copied to clipboard

Setting customValidate in vue-tel-input hung my page deadly

Open PetroGromovo opened this issue 3 years ago • 4 comments

Hello, I added https://github.com/EducationLink/vue-tel-input to my bootstrap-vue project and looking at customValidate property I want to make validation to phone number like “(123) 456-7890”. I suppose that customValidate is javascript regex validation and googled this https://stackoverflow.com/questions/4338267/validate-phone-number-with-javascript branch I try several methods from it, like :

My regex of choice is:

/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im

But setting this property :

        <vue-tel-input
                :onCountryChanged="countryChangedEvent"
                :preferredCountries="['AU', 'BR']"
                :onlyCountries="['AU', 'BR', 'UA']"
                :enabledCountryCode="true"
                :defaultCountry="'AU'"
                v-model="phone"
                :selectedCountryCode="true"
                autocomplete="off"
                name= "telephone"

                :custom-validate="/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im"
                wrapperClasses="m-4 p-4"
                inputClasses="w-full"

                :maxLen="25"
                mode="international"
                :disabledFetchingCountry="false"
                :disabled="false"
                :disabledFormatting="false"
                :placeholder="'Enter a phone number'"
                @onClose="onClose"
                @onInput="onInput"
        ></vue-tel-input>

my page hung deadly

I tried some more regex samples with the same results. Is it invalid format or I need some wrapper ?

    "bootstrap-vue": "^2.3.0",
    "vue": "^2.6.11",
    "vue-tel-input": "^4.4.0",

Thanks!

PetroGromovo avatar Jul 10 '20 15:07 PetroGromovo

I am experiencing the same issue

Chup4Chups avatar Jul 28 '20 08:07 Chup4Chups

I got some hints here : https://forum.vuejs.org/t/setting-customvalidate-in-vue-tel-input-hung-my-page-deadly/99926/2 But it did not help me...

PetroGromovo avatar Jul 29 '20 10:07 PetroGromovo

You pass the props value like this :custom-validate="phoneValue === '' ? false : /^[0-9]+$/". Make sure your value cannot be null or undefined when your component is mount.

Hasnain-js avatar Feb 06 '24 09:02 Hasnain-js

The issue you are experiencing is because when the component is mounted, the initial value of your phone number field is empty. Add into your regex possiblity that it can be empty ^$ and you should be fine

gentlekenny avatar Apr 04 '24 06:04 gentlekenny