PageSourceSearch

https://www.piaselect.com/wp-content/themes/hello-elementor-child/js/jquery-input-mask-phone-number.js

js piaselect.com collected 2026-10-08 03:50:06 UTC 4,955 bytes, 122 lines download raw bytes

1// ==================================================
2// 
3// jquery-input-mask-phone-number 1.0.14
4//
5// Licensed (The MIT License)
6// 
7// Copyright © Raja Rama Mohan Thavalam <[email protected]>
8//
9// Last Updated On: 22/Aug/2020 IST  12:05 AM 
10//
11// ==================================================
12
13(function ($) {
14    $.fn.usPhoneFormat = function (options) {
15        var params = $.extend({
16            format: 'xxx-xxx-xxxx',
17            international: false,
18
19        }, options);
20
21        if (params.format === 'xxx-xxx-xxxx') {
22            $(this).bind('paste', function (e) {
23
24                e.preventDefault();
25                var inputValue = e.originalEvent && e.originalEvent.clipboardData.getData('Text');
26                inputValue = inputValue.replace(/\D/g, '');
27                if (!$.isNumeric(inputValue)) {
28                    return false;
29                } else {
30                    if (inputValue.length > 9) {
31                        inputValue = String(inputValue.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3"));
32                    } else {
33                        inputValue = String(inputValue.replace(/(\d{3})(?=\d)/g, '$1-'));
34                    }
35                    $(this).val(inputValue);
36                    $(this).val('');
37                    inputValue = inputValue.substring(0, 12);
38                    $(this).val(inputValue);
39                }
40            });
41            $(this).on('keydown touchend', function (e) {
42
43                e = e || window.event;
44                var key = e.which || e.keyCode; // keyCode detection
45                var ctrl = e.ctrlKey || e.metaKey || key === 17; // ctrl detection
46                if (key == 86 && ctrl) { // Ctrl + V Pressed !
47
48                } else if (key == 67 && ctrl) { // Ctrl + C Pressed !
49
50                } else if (key == 88 && ctrl) { // Ctrl + x Pressed !
51
52                } else if (key == 65 && ctrl) { // Ctrl + a Pressed !
53                    $(this).trigger("paste");
54                } else if (key != 9 && e.which != 8 && e.which != 0 && !(e.keyCode >= 96 && e.keyCode <= 105) && !(e.keyCode >= 48 && e.keyCode <= 57)) {
55                    return false;
56                }
57                var curchr = this.value.length;
58                var curval = $(this).val();
59                if (curchr == 3 && e.which != 8 && e.which != 0) {
60                    $(this).val(curval + "-");
61                } else if (curchr == 7 && e.which != 8 && e.which != 0) {
62                    $(this).val(curval + "-");
63                }
64                $(this).attr('maxlength', '12');
65            });
66
67        } else if (params.format === '(xxx) xxx-xxxx') {
68            $(this).on('keydown touchend', function (e) {
69
70                e = e || window.event;
71                var key = e.which || e.keyCode; // keyCode detection
72                var ctrl = e.ctrlKey || e.metaKey || key === 17; // ctrl detection
73                if (key == 86 && ctrl) { // Ctrl + V Pressed !
74
75                } else if (key == 67 && ctrl) { // Ctrl + C Pressed !
76
77                } else if (key == 88 && ctrl) { //Ctrl + x Pressed
78
79                } else if (key == 65 && ctrl) { //Ctrl + a Pressed !
80                    $(this).trigger("paste");
81                } else if (key != 9 && e.which != 8 && e.which != 0 && !(e.keyCode >= 96 && e.keyCode <= 105) && !(e.keyCode >= 48 && e.keyCode <= 57)) {
82                    return false;
83                }
84                var curchr = this.value.length;
85                var curval = $(this).val();
86                if (curchr == 3 && e.which != 8 && e.which != 0) {
87                    $(this).val('(' + curval + ')' + " ");
88                } else if (curchr == 9 && e.which != 8 && e.which != 0) {
89                    $(this).val(curval + "-");
90                }
91                $(this).attr('maxlength', '14');
92
93            });
94            $(this).bind('paste', function (e) {
95
96                e.preventDefault();
97                var inputValue = e.originalEvent && e.originalEvent.clipboardData.getData('Text');
98                inputValue = inputValue.replace(/\D/g, '');
99
100                if (!$.isNumeric(inputValue)) {
101                    return false;
102                } else {
103
104                    if (inputValue.length > 9) {
105                        inputValue = String(inputValue.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3"));
106                    } else if (inputValue.length > 6) {
107                        inputValue = String(inputValue.replace(/(\d{3})(\d{3})(?=\d)/g, '($1) $2-'));
108                    } else if (inputValue.length > 3) {
109                        inputValue = String(inputValue.replace(/(\d{3})(?=\d)/g, '($1) '));
110                    }
111
112                    $(this).val(inputValue);
113                    $(this).val('');
114                    inputValue = inputValue.substring(0, 14);
115                    $(this).val(inputValue);
116                }
117            });
118
119        }
120        
121    }
122}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.