Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('input[type="tel"]').inputmask("phone", {
- onKeyValidation: function () {
- mask = $(this).inputmask("getmetadata")["mask"];
- pattern = "";
- // console.log(mask);
- console.log("length: ");
- console.log($(this).val().length);
- index = mask.indexOf("(");
- if (index > 0) {
- index2 = mask.indexOf(")");
- index3 = index2 - index - 1;
- // console.log(index3);
- mask = mask.substr(index2+1);
- // console.log(mask);
- arr = mask.split('-');
- // console.log(arr);
- index4 = arr[0].length;
- index5 = arr[1].length;
- index6 = arr[2].length;
- index = index-1;
- // console.log(index);
- index = 1;
- index2 = 3;
- pattern = '^[+]\d{'+index+'}\\';
- pattern = pattern + '(\\d{'+index2+'}\\)';
- arr.forEach(function(entry) {
- pattern = pattern + '-\\d{'+ entry.length +'}';
- console.log(entry);
- });
- pattern = pattern + '$';
- pattern = '^[+]\\d{1}\\(\\d{3}\\)\\d{3}-\\d{2}-\\d{2}$';
- console.log(pattern);
- // pattern = '^[+]\d{1}\(\d{3}\)\d{3}-\d{2}-\d{2}$';
- // pattern = '^[+]\\d{'+ index +'}\\(\\d{'+ index3 +'}\\)\\d{'+ index4 +'}(-\\d{'+ index5 +'}){'+ index6 +'}$';
- } else {
- // console.log(mask);
- index = mask.indexOf("-");
- index2 = mask.indexOf("-");
- index3 = index2 - index - 1;
- mask = mask.substr(index2+1);
- console.log(mask);
- index = mask.indexOf("-");
- arr = mask.split('-');
- // console.log(arr.length);
- // index4 = arr[0].length;
- // index5 = arr[1].length;
- // index6 = arr[2].length;
- // index = index-1;
- // console.log(index);
- index = 3;
- pattern = '^[+]\\d{'+ index +'}';
- arr.forEach(function(entry) {
- pattern = pattern + '-\\d{'+ entry.length +'}';
- console.log(entry);
- });
- pattern = pattern + '$';
- }
- // $(this).attr({
- // 'pattern': pattern
- // });
- }
- });
Add Comment
Please, Sign In to add comment