-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
125 lines (103 loc) · 6.49 KB
/
Copy pathvalidate.js
File metadata and controls
125 lines (103 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const validateDni = (dni) => {
const validChars = 'TRWAGMYFPDXBNJZSQVHLCKET'
const nifRexp = /^[0-9]{8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i
const nieRexp = /^[XYZ]{1}[0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i
const str = dni.toString().toUpperCase()
if(!nifRexp.test(str) && !nieRexp.test(str)) console.log('DNI incorrecto')
const nie = str
.replace(/^[X]/, '0')
.replace(/^[Y]/, '1')
.replace(/^[Z]/, '2')
const letter = str.substr(-1)
const charIndex = parseInt(nie.substr(0, 8)) % 23
if(validChars.charAt(charIndex) === letter) console.log('DNI válido')
console.log('DNI incorrecto')
}
const validateEmail = (email) => {
const emailRegex = /^(([^<>()\[\]\\.,:\s@"]+(\.[^<>()\[\]\\.,:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if(emailRegex.test(email)) console.log('email válido')
else console.log('email incorrecto')
}
const validateIban = (iban) => {
const ibanRegex = /([A-Z]{2})\s*\t*(\d\d)\s*\t*(\d\d\d\d)\s*\t*(\d\d\d\d)\s*\t*(\d\d)\s*\t*(\d\d\d\d\d\d\d\d\d\d)/g
if(ibanRegex.test(iban)) console.log('iban válido')
else console.log('iban incorrecto')
}
const validatePasswordComplex = (password) => {
//Should have 1 lowercase letter, 1 uppercase letter, 1 number, 1 special character and be at least 8 characters long
const passwordRegex = /(?=(.*[0-9]))(?=.*[\!@#$%^&*()\\[\]{}\-_+=~`|:"'<>,./?])(?=.*[a-z])(?=(.*[A-Z]))(?=(.*)).{8,}/
if(passwordRegex.test(password)) console.log('password válido')
else console.log('password incorrecto')
}
const validatePasswordModerate = (password) => {
//Should have 1 lowercase letter, 1 uppercase letter, 1 number, and be at least 8 characters long
const passwordRegex = /(?=(.*[0-9]))((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.{8,}$/
if(passwordRegex.test(password)) console.log('password válido')
else console.log('password incorrecto')
}
const validateUsername = (username) => {
//Alphanumeric string that may include _ and – having a length of 3 to 16 characters –
const usernameRegex = /^[a-z0-9_-]{3,16}$/
if(usernameRegex.test(username)) console.log('username válido')
else console.log('username incorrecto')
}
const validateUrl = (url) => {
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)/
if(urlRegex.test(url)) console.log('url válida')
else console.log('url incorrecta')
}
const validateIP = (ip) => {
const ipRegex = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/g
if(ipRegex.test(ip)) console.log('ip válida')
else console.log('ip incorrecta')
}
const validateHexadecimal = (hexadecimal) => {
const hexadecimalRegex = /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
if(hexadecimalRegex.test(hexadecimal)) console.log('hexadecimal válido')
else console.log('hexadecimal incorrecto')
}
const validateCreditCard = (card) => {
const creditCardRegex = /^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/
if(creditCardRegex.test(card)) console.log('card válido')
else console.log('card incorrecto')
}
this.socialMediaList = [ // Ezequiel Navarta (Gracias!)
{
type: "other",
regexp: new RegExp(/[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%.\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%\+.~#?&//=]*)/),
icon: "fad fa-globe-americas social-icon"
}, {
type: "facebook",
regexp: new RegExp(/(?:https?:\/\/)?(?:www\.)?(?:facebook|fb)\.com/),
icon: "fab fa-facebook social-icon"
}, {
type: "instagram",
regexp: new RegExp(/(?:https?:\/\/)?(?:www\.)?(?:instagram\.com|instagr\.am)\/([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/),
icon: "fab fa-instagram social-icon"
}, {
type: "twitter",
regexp: new RegExp(/(?:https?:\/\/)?(?:[A-z]+\.)?twitter\.com\/@?(?!home|sharegexp|privacy|tos)([A-z0-9_]+)\/?/),
icon: "fab fa-twitter social-icon"
}, {
type: "youtube",
regexp: new RegExp(/(?:https?:\/\/)?(?:[A-z]+\\.)?youtube.com\/channel\/([A-z0-9-\\_]+)\/?/),
icon: "fab fa-youtube social-icon"
}
];
private esExtensionArchivoPermitida(nombreArchivo:string){ // Manuel Hernandez => https://www.linkedin.com/in/manuel-hernandez-barahona-angular/ (Gracias!)
const extensionesPermitidas = [
'xlsx','xls',
'docx','doc',
'pdf','msg',
'png','jpg','jpeg']
return extensionesPermitidas.some( extension => new RegExp(`(\.${extension})$`,'i').test(nombreArchivo))
}
function removeSpaces (text:string){ // Manuel Hernandez => https://www.linkedin.com/in/manuel-hernandez-barahona-angular/ (Gracias!)
return text.replace(/ /g,'');
}
function removeDots(text:string) { // Manuel Hernandez => https://www.linkedin.com/in/manuel-hernandez-barahona-angular/ (Gracias!)
return text.replace(/\./g,'');
}
function removeHyphens(text:string) { // Manuel Hernandez => https://www.linkedin.com/in/manuel-hernandez-barahona-angular/ (Gracias!)
return text.replace(/\-/g,'');
}