iOS判断是否是表情和邮箱格式的判断

1.该方法是从论坛上看到的,,自己用啦下  感觉挺好用,在这里做个备忘吧 !!!!!

2.应用环境,用户输入昵称的时候,不可以输入 表情

- (BOOL)stringContainsEmoji:(NSString *)string {

__block
BOOL returnValue =NO;

[string enumerateSubstringsInRange:NSMakeRange(0, [stringlength])
options:NSStringEnumerationByComposedCharacterSequencesusingBlock:

^(NSString *substring,NSRange substringRange,
NSRange enclosingRange,
BOOL *stop) {

const
unichar hs = [substringcharacterAtIndex:0];

// surrogate pair

if (0xd800 <= hs && hs <= 0xdbff) {

if (substring.length > 1) {

const
unichar ls = [substringcharacterAtIndex:1];

const
int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;

if (0x1d000 <= uc && uc <= 0x1f77f) {

returnValue =YES;

}

}

}else
if (substring.length > 1) {

const
unichar ls = [substringcharacterAtIndex:1];

if (ls == 0x20e3) {

returnValue =YES;

}

}else {

// non surrogate

if (0x2100 <= hs && hs <= 0x27ff) {

returnValue =YES;

}else
if (0x2B05 <= hs && hs <= 0x2b07) {

returnValue =YES;

}else
if (0x2934 <= hs && hs <= 0x2935) {

returnValue =YES;

}else
if (0x3297 <= hs && hs <= 0x3299) {

returnValue =YES;

}else
if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {

returnValue =YES;

}

}

}];

return returnValue;

}

//邮箱的判读

//判断是否是邮箱格式

-(BOOL)isValidateEmail:(NSString *)email

{

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:email];

}

时间: 2024-10-01 00:26:33

iOS判断是否是表情和邮箱格式的判断的相关文章

判断一个java文件和邮箱格式是否合法

import java.util.Scanner; public class StringTest { public static void main(String[] args) { int back = 1; Scanner input  =new Scanner(System.in); do{                                                                                  //设置循环方法,直至输入正确为止

jQuery邮箱格式验证代码

jQuery邮箱格式验证代码:在表单提交的时候可能需要用到邮箱验证代码,代码比较简单,就是邮箱格式的判断,如果说有难点可能就是关于正则表达式的使用,这里就不多说了,大家可以自行查询,下面就给出一段可以使用的验证代码,复制黏贴即可.代码实例如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content=&quo

在js中实现邮箱格式的验证

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>在此处插入标题</title><script type="tex

iOS开发——判断邮箱格式

//判断邮箱格式 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex]; ret

判断 邮箱格式是否正确

练习:判断邮箱格式是否正确1.有且只能有一个@2.不能以@开头[email protected]之后至少有一个.[email protected]和.不能靠在一起5.不能以.结尾 1 Console.Write("请输入邮箱地址:"); 2 string m = Console.ReadLine(); 3 if (m.IndexOf("@") == m.LastIndexOf("@")) 4 { 5 if (m.IndexOf("@&q

判断邮箱 格式是否正确

/练习:判断邮箱格式是否正确 //1.有且只能有一个@ contains @ indexof @=lastindexof //2.不能以@开头 indexof != 0 //[email protected]之后至少有一个. //[email protected]和.不能靠在一起 //5.不能以.结尾 Console.Write("请输入您的邮箱:"); string s = Console.ReadLine(); if(s.Contains("@")==true)

判断邮箱格式和图片压缩

1.判断邮箱格式 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex [email protected]"[A-Z0-9a-z._%+-][email protected][A-Za- z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",e

jquery判断邮箱格式问题

方法一: var search_str = /^[\w\-\.][email protected][\w\-\.]+(\.\w+)+$/; var email_val = $("#Email").val(); if(!search_str.test(email_val)){ alert("please input right email !"); $('#Email').focus(); return false; } 方法二: ar mail = $('#mail

3月12日 判断邮箱格式是否正确

//练习:判断邮箱格式是否正确 //1.有且只能有一个@ //2.不能以@开头 //[email protected]之后至少有一个. //[email protected]和.不能靠在一起 //5.不能以.结尾 Console.Write("请输入您的邮箱账号"); string mail = Console.ReadLine(); bool a = mail.Contains("@"); if (a == true) { int b = mail.IndexOf