23.swift-正则

2021-07-24  本文已影响0人  ChaosHeart
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;
    }
    
}
上一篇下一篇

猜你喜欢

热点阅读