HK number 驗證
判斷以8位數(shù)為標準的695807開頭的number
static func isHKphone(phone:String) -> Bool {
let hkphone = "^(6|9|5|8|0|7)\\d{7}$"
let regexMobile = NSPredicate(format:"SELF MATCHES %@",hkphone)
if regexMobile.evaluate(with: phone) == true {
return true
}else{
return false
}
}
Email驗證
判斷以xxxxx@xxx.xx為標準的email
static func isEmail(email:String) -> Bool {
let emailRegular = "^([a-zA-Z0-9]+([._\\-])*[a-zA-Z0-9]*)+@([a-zA-Z0-9])+(.([a-zA-Z])+)+$"
let regexMobile = NSPredicate(format:"SELF MATCHES %@",emailRegular)
if regexMobile.evaluate(with: email) == true {
return true
}else{
return false
}
}
特定Email驗證
判斷特定Email后綴的驗證
static func isBelowemail(email:String) -> Bool {
let emailRegular = "^([a-zA-Z0-9]+([._\\-])*[a-zA-Z0-9]*)+@([a-zA-Z0-9])+(.([a-zA-Z])+)+$"
let regexMobile = NSPredicate(format:"SELF MATCHES %@",emailRegular)
if regexMobile.evaluate(with: email) == true {
/**
judge below email
? @pccw.com
? @hkcsl.com
? @pcpd.com
? @pccwglobal.com
? @viu.tv
**/
if let index = email.characters.index(of: "@") {
let belowEmail = String(email.characters.suffix(from: index))
switch belowEmail{
case "@pccw.com":
return true
case "@hkcsl.com":
return true
case "@pcpd.com":
return true
case "@pccwglobal.com":
return true
case "@viu.tv":
return true
default:
return false
}
}
return false
}else{
return false
}
}
PWD驗證
判斷必須有一個大寫字母鸡挠,小寫字母,數(shù)字8位數(shù)以上的PWD
static func isPassword(password:String) -> Bool{
let passwordRegular = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z0-9])[a-zA-Z[^A-Za-z0-9]\\d]{8,}$"
let regexMobile = NSPredicate(format:"SELF MATCHES %@",passwordRegular)
if regexMobile.evaluate(with: password) == true {
return true
}else{
return false
}
}