|
|
import Foundation
|
|
|
|
|
|
class Entity {
|
|
|
var ID: String = ""
|
|
|
var name: String = ""
|
|
|
func verify() -> Bool {
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字的情况,可以直接照搬
|
|
|
let reFormula = try! NSRegularExpression(pattern: "^\\d{13}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
if matchList.count != 1 {
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class Student: Entity {
|
|
|
override func verify() -> Bool {
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字,以20xx开头,第5位为1-3的情况,可以直接照搬
|
|
|
let reFormula = try! NSRegularExpression(pattern: "^20\\d{2}[1-3]\\d{8}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
if matchList.count != 1 {
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class Cat: Entity {
|
|
|
override func verify() -> Bool {
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字,开头为0000的情况,可以直接照搬
|
|
|
let reFormula = try! NSRegularExpression(pattern: "^0000\\d{9}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
if matchList.count != 1 {
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字,以20xx开头,第5位为1-3的情况,可以直接照搬
|
|
|
// let reFormula = try! NSRegularExpression(pattern: "^20\\d{2}[1-3]\\d{8}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
// let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
// if matchList.count != 1 {
|
|
|
// return false
|
|
|
// }
|
|
|
// return true
|
|
|
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字的情况,可以直接照搬
|
|
|
// let reFormula = try! NSRegularExpression(pattern: "^\\d{13}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
// let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
// if matchList.count != 1 {
|
|
|
// return false
|
|
|
// }
|
|
|
// return true
|
|
|
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字,开头为0000的情况,可以直接照搬
|
|
|
// let reFormula = try! NSRegularExpression(pattern: "^0000\\d{9}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
// let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
// if matchList.count != 1 {
|
|
|
// return false
|
|
|
// }
|
|
|
// return true
|
|
|
|
|
|
|
|
|
//测试用,不需要改动
|
|
|
var fly = Entity()
|
|
|
fly.ID = "0000000099003"
|
|
|
fly.name = "蒼蠅"
|
|
|
fly.verify()
|
|
|
|
|
|
var siuming = Student()
|
|
|
siuming.ID = "2021502233076"
|
|
|
siuming.name = "小明"
|
|
|
siuming.verify()
|
|
|
|
|
|
var siuhung = Student()
|
|
|
siuhung.ID = "2022302191000"
|
|
|
siuhung.name = "小紅"
|
|
|
siuhung.verify()
|
|
|
|
|
|
var policecat = Cat()
|
|
|
policecat.ID = "0000999988222"
|
|
|
policecat.name = "警長"
|
|
|
policecat.verify()
|