Skip to content

Commit ff614b7

Browse files
committed
Return type
using returnType variable you can know the current type filled by user
1 parent 9fbb18a commit ff614b7

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
jquery.mask.js

example.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<script type="text/javascript">
1919
$(document).ready(function () {
2020
$('.validate').cpfcnpj({
21-
mask: false,
21+
mask: true,
2222
validate: 'cpfcnpj',
2323
event: 'click',
2424
//validateOnlyFocus: true,
2525
handler: '.btn',
26-
ifValid: function (input) { input.removeClass("error"); },
27-
ifInvalid: function (input) { input.addClass("error"); }
26+
ifValid: function (input) { input.removeClass("error"); alert(returnType); },
27+
ifInvalid: function (input) { input.addClass("error"); alert(returnType); }
2828
});
2929
});
3030
</script>

jquery.cpfcnpj.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*!
2-
* jQuery CPF/CNPJ Validator Plugin v1.1.3
2+
* jQuery CPF/CNPJ Validator Plugin v1.1.4
33
* Developed by: Guilherme Gomes ([email protected])
4-
* Date: 2018-08-02
4+
* Date: 2019-02-23
55
*/
66
(function ($) {
7-
var type = null;
8-
97
$.fn.cpfcnpj = function (options) {
108
// Default settings
119
var settings = $.extend({
@@ -15,7 +13,8 @@
1513
handler: $(this),
1614
validateOnlyFocus: false,
1715
ifValid: null,
18-
ifInvalid: null
16+
ifInvalid: null,
17+
returnType: null
1918
}, options);
2019

2120
if (settings.mask) {
@@ -58,6 +57,7 @@
5857
if (!settings.validateOnlyFocus || settings.validateOnlyFocus && control.is(':focus')) {
5958
var value = control.val();
6059
var lgt = value.length;
60+
returnType = null;
6161

6262
valid = false;
6363

@@ -71,11 +71,11 @@
7171
else if (settings.validate == 'cpfcnpj') {
7272
if (validate_cpf(value, settings.mask)) {
7373
valid = true;
74-
type = 'cpf';
74+
returnType = 'cpf';
7575
}
7676
else if (validate_cnpj(value, settings.mask)) {
7777
valid = true;
78-
type = 'cnpj';
78+
returnType = 'cnpj';
7979
}
8080
}
8181
}
@@ -189,4 +189,4 @@
189189

190190
return false;
191191
}
192-
}(jQuery));
192+
}(jQuery));

jquery.cpfcnpj.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)