美文网首页
实用正则表达式

实用正则表达式

作者: iOS苦逼开发 | 来源:发表于2017-07-17 12:09 被阅读13次

    1、判断邮箱格式(swift)

    let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
    let testEmail = NSPredicate(format:"SELF MATCHES %@", regex)
    let status =  testEmail.evaluateWithObject(emailText)//BOOL
    

    2、判断是否是手机号(OC)

    - (BOOL)isPhoneNum{
        NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";
        NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
        return [regextestmobile evaluateWithObject:self.numberTF.text];
    }
    

    相关文章

      网友评论

          本文标题:实用正则表达式

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