How to an element in a validator function in parsley.JS
I am trying to make a custom validator in parsley.js and currently i have the following:
- window.Parsley.addValidator('intlTelNo' , {
- requirementType : 'integer',
- validateNumber : (val , requirement ) => {
- console.log(val);
- return true;
- },
- messages : {
- en : 'Please enter a valid phone number.'
- }
- });
I am using this validator in my HTML like so:
- <input type="" name="Phone" placeholder="Phone" id="intl-phone-number" data-parsley-intl-tel-no data-parsley-trigger="focusin focusout" data-parsley-errors-container="#error-container">
My custom validator gets used on the above input because i have specified the following data attribute:
- data-parsley-intl-tel-no
ofcourse i am returning true as of now in my custom validator so the tests always passes, but what i really want to do is check if the value of the input is a valid phone number and for that i need to access the input itself (Yes the input itself and not just the value as i am using some third party JS library that needs the input and not just the value ).
Now , How do i pass the input into the below function ?
- validateNumber : (val , requirement ) => {
- console.log(val);
- return true;
- },
Is there some javascript magic technique that i can use ? as right now i am just sitting here scratching my head :| . Would really appreciate any help :)
P.S. An example of how to make a custom validator can be seen
HERE.