You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
726 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import Foundation
struct Entity {
let ID, 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
}
}
var fly = Entity(ID: "0000000000987", name: "蒼蠅")
fly.verify()
var xiaoming = Entity(ID: "20211145145141919810", name: "可利斯")
xiaoming.verify()