| 1 |
efrain |
1 |
//
|
|
|
2 |
// Validators.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 7/20/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import Foundation
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
class Validator
|
|
|
12 |
{
|
|
|
13 |
public static func checkEmail(email : String) -> Bool {
|
|
|
14 |
let regex = #"^[a-zA-Z0-9_\-\.~]{2,}@[a-zA-Z0-9_\-\.~]{2,}\.[a-zA-Z]{2,}$"#
|
|
|
15 |
|
|
|
16 |
let predicate = NSPredicate(format: "SELF MATCHES %@", regex)
|
|
|
17 |
return predicate.evaluate(with: email) ? true : false;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public static func checkPassword(password : String) -> Bool {
|
|
|
21 |
|
|
|
22 |
/*
|
|
|
23 |
let regexOld = #"^(?=.*\d+)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{6,16}$"#
|
|
|
24 |
let regexNew = #"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[\#\?\!\@\$\^\%\*\-]).{6,16}$"#
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
let regexPassword = #"(^(?=.*\d+)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{6,16}$|^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[\#\?\!\@\$\^\%\*\-]).{6,16}$)"#
|
|
|
28 |
|
|
|
29 |
let predicate = NSPredicate(format: "SELF MATCHES %@", regexPassword)
|
|
|
30 |
|
|
|
31 |
if(predicate.evaluate(with: password)) {
|
|
|
32 |
return true
|
|
|
33 |
|
|
|
34 |
} else {
|
|
|
35 |
return false
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
}
|