-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.php
More file actions
54 lines (49 loc) · 1.1 KB
/
Copy pathvalidation.php
File metadata and controls
54 lines (49 loc) · 1.1 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
<?php
// validation.php
/**
* Valida texto: letras (incluidos acentos y enie), espacios, guion y apostrofe.
* Permite apellidos compuestos como "Garcia-Lopez" o "O'Brien".
*
* @param string $text
* @return bool
*/
function validateText($text) {
return (bool) preg_match("/^[a-zA-ZáéíóúÁÉÍÓÚñÑüÜ\s'\-]+$/u", (string) $text);
}
/**
* Valida un correo electronico.
*
* @param string $email
* @return bool
*/
function validateEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}
/**
* Valida que el valor sea un entero.
*
* @param mixed $number
* @return bool
*/
function validateNumber($number) {
return filter_var($number, FILTER_VALIDATE_INT) !== false;
}
/**
* Valida una contrasena: minimo 8 caracteres.
*
* @param string $password
* @return bool
*/
function validatePassword($password) {
return strlen((string) $password) >= 8;
}
/**
* Valida un identificador: entero positivo (> 0).
*
* @param mixed $v
* @return bool
*/
function validateId($v) {
$val = filter_var($v, FILTER_VALIDATE_INT);
return $val !== false && $val > 0;
}