美文网首页
23.swift-正则

23.swift-正则

作者: ChaosHeart | 来源:发表于2021-07-24 08:04 被阅读0次
    import UIKit
    
    class Regular: NSObject {
        
        /*
         + (BOOL)regular_Phone:(NSString *)Phone
         {
             NSString *pattern = @"^1+[13456789]+\\d{9}";
             NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
             BOOL isMatch = [pred evaluateWithObject:Phone];
             return isMatch;
         }
         */
    
        ///加@objc 为了方便OC类调用
        @objc func regular_Phone(Phone : String) -> Bool {
            let pattern = "^1+[13456789]+\\d{9}";
            let pred = NSPredicate.init(format: "SELF MATCHES %@", pattern);
            let isResult = pred.evaluate(with: Phone);
            return isResult;
        }
        
    }
    

    相关文章

      网友评论

          本文标题:23.swift-正则

          本文链接:https://www.haomeiwen.com/subject/harzlltx.html