prolab-api/vendor/bower-asset/inputmask/lib/extensions/inputmask.extensions.js

133 lines
4.2 KiB
JavaScript
Raw Normal View History

2025-09-24 06:24:52 +00:00
/*
Input Mask plugin extensions
2025-10-03 11:00:05 +00:00
http://github.com/RobinHerbots/jquery.inputmask
2025-09-24 06:24:52 +00:00
Copyright (c) Robin Herbots
Licensed under the MIT license
*/
import Inputmask from "../inputmask";
2025-10-03 11:00:05 +00:00
import {getLastValidPosition} from "../positioning";
import {getMaskTemplate} from "../validation-tests";
//extra definitions
2025-09-24 06:24:52 +00:00
Inputmask.extendDefinitions({
2025-10-03 11:00:05 +00:00
"A": {
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
casing: "upper" //auto uppercasing
},
"&": { //alfanumeric uppercasing
validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
casing: "upper"
},
"#": { //hexadecimal
validator: "[0-9A-Fa-f]",
casing: "upper"
}
2025-09-24 06:24:52 +00:00
});
2025-10-03 11:00:05 +00:00
var ipValidatorRegex = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
2025-09-24 06:24:52 +00:00
function ipValidator(chrs, maskset, pos, strict, opts) {
2025-10-03 11:00:05 +00:00
if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
chrs = maskset.buffer[pos - 1] + chrs;
if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
chrs = maskset.buffer[pos - 2] + chrs;
} else chrs = "0" + chrs;
} else chrs = "00" + chrs;
return ipValidatorRegex.test(chrs);
2025-09-24 06:24:52 +00:00
}
2025-10-03 11:00:05 +00:00
2025-09-24 06:24:52 +00:00
Inputmask.extendAliases({
2025-10-03 11:00:05 +00:00
"cssunit": {
regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
2025-09-24 06:24:52 +00:00
},
2025-10-03 11:00:05 +00:00
"url": { //needs update => https://en.wikipedia.org/wiki/URL
regex: "(https?|ftp)://.*",
autoUnmask: false,
keepStatic: false,
tabThrough: true
2025-09-24 06:24:52 +00:00
},
2025-10-03 11:00:05 +00:00
"ip": { //ip-address mask
mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}",
definitions: {
"i": {
validator: ipValidator
},
"j": {
validator: ipValidator
},
"k": {
validator: ipValidator
},
"l": {
validator: ipValidator
}
},
onUnMask: function (maskedValue, unmaskedValue, opts) {
return maskedValue;
},
inputmode: "decimal",
substitutes: {",": "."}
2025-09-24 06:24:52 +00:00
},
2025-10-03 11:00:05 +00:00
"email": {
//https://en.wikipedia.org/wiki/Domain_name#Domain_name_space
//https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
//should be extended with the toplevel domains at the end
mask: function ({separator, quantifier}) {
var emailMask = "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]";
var mask = emailMask;
if (separator) {
for (let i = 0; i < quantifier; i++) {
mask += `[${separator}${emailMask}]`;
}
}
return mask;
},
greedy: false,
casing: "lower",
separator: null,
quantifier: 5,
skipOptionalPartCharacter: "",
onBeforePaste: function (pastedValue, opts) {
pastedValue = pastedValue.toLowerCase();
return pastedValue.replace("mailto:", "");
},
definitions: {
"*": {
validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]"
},
"-": {
validator: "[0-9A-Za-z-]"
}
},
onUnMask: function (maskedValue, unmaskedValue, opts) {
return maskedValue;
},
inputmode: "email"
2025-09-24 06:24:52 +00:00
},
2025-10-03 11:00:05 +00:00
"mac": {
mask: "##:##:##:##:##:##"
2025-09-24 06:24:52 +00:00
},
2025-10-03 11:00:05 +00:00
//https://en.wikipedia.org/wiki/Vehicle_identification_number
// see issue #1199
"vin": {
mask: "V{13}9{4}",
definitions: {
"V": {
validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
casing: "upper"
}
},
clearIncomplete: true,
autoUnmask: true
2025-09-24 06:24:52 +00:00
},
2025-10-03 11:00:05 +00:00
//http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/
//https://en.wikipedia.org/wiki/Social_Security_number
"ssn": {
mask: "999-99-9999",
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
var bffr = getMaskTemplate.call(this, true, getLastValidPosition.call(this), true, true);
return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(bffr.join(""));
}
2025-09-24 06:24:52 +00:00
},
});