大家好,又見面了,我是你們的朋友全棧君。
//進行郵箱正規表達式判斷
-(BOOL) validateEmail
{
NSString *emailRegex = @”[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}”;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@”SELF MATCHES %@”, emailRegex];
return [emailTest evaluateWithObject:self];
}
這裡面的self 是因為這個方法是寫在category的 NSString + SiZheString.m 中
是以調取方式應該是
if([@”字元串” validateEmail]){
}
這種樣式
如果是自己不想封裝
NSString *emailRegex = @”[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}”;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@”SELF MATCHES %@”, emailRegex];
Bool isTrue = [emailTest evaluateWithObject:@”字元串”];
釋出者:全棧程式員棧長,轉載請注明出處:https://javaforall.cn/149472.html原文連結:https://javaforall.cn