jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. Now includes React and Vue components.
https://intl-tel-input.com
MIT License
7.58k stars 1.94k forks source link

Using with jquery validation #864

Closed TheMurseL closed 5 years ago

TheMurseL commented 5 years ago

Hello,

I have a problem. i couldn't solve this problem.

Uncaught TypeError: $(...).intlTelInput is not a function. Exception occurred when checking element site-phone, check the 'intlTelNumber' method. at $.validator. (1dabdf0487bbd9409effa79e8a16689b.js:2982) at $.validator.check (1dabdf0487bbd9409effa79e8a16689b.js:2012) at $.validator.element (1dabdf0487bbd9409effa79e8a16689b.js:1776) at $.validator.onkeyup (1dabdf0487bbd9409effa79e8a16689b.js:1631) at HTMLInputElement.delegate (1dabdf0487bbd9409effa79e8a16689b.js:1716) at HTMLFormElement.dispatch (jquery-min.js:1) at HTMLFormElement.r.handle (jquery-min.js:1)

/ FORM INLINE CONTROL /

GLOBAL_PHONE: { required: true, // field is mandatory intlTelNumber: true // must contain a valid phone number },

/ FORM INLINE CONTROL /

/ ADDEVENT /

// create a custom phone number rule called 'intlTelNumber'
jQuery.validator.addMethod("intlTelNumber", function(value, element) {
    return this.optional(element) || $(element).intlTelInput("isValidNumber");
}, "Please enter a valid International Phone Number");

/ ADDEVENT /

jackocnr commented 5 years ago

What is $.validator? Is that a plugin you're using? I'm not familiar with that. I'm afraid this is outside the scope of this plugin - I'd recommend you ask for help on StackOverflow.

TheMurseL commented 5 years ago

i am using https://jqueryvalidation.org/ script.

this is rule;

$(this).parents('form').validate({ rules: {
GLOBAL_PHONE: { required: true, intlTelNumber: true // must contain a valid phone number },
}, ... ... ... ... ... });

jackocnr commented 5 years ago

Thanks for clarifying, but yeah as I say, I'm afraid this is outside the scope of this plugin - I'd recommend you ask for help on StackOverflow.