js判断邮箱格式是否正确 的几个例子

判断邮箱格式是否正确

 

- (void)viewDidLoad  
{  
    [super viewDidLoad];  
    // Do any additional setup after loading the view.  
    emailTextField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 50)];  
    emailTextField.backgroundColor = [UIColor lightGrayColor];  
    [self.view addSubview:emailTextField];  
      
      
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    button.frame = CGRectMake(100, 170, 150, 50);  
    [button setTitle:@"注册" forState:UIControlStateNormal];  
    [button addTarget:self action:@selector(registor:) forControlEvents:UIControlEventTouchUpInside];  
    [self.view addSubview:button];  
}  
- (void)registor:(UIButton *)button  
{  
    if([self isValidateEmail:emailTextField.text]){  
        NSLog(@"邮箱格式正确");  
    }else {  
        NSLog(@"不是");  
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"错误" message:@"请输入正确的邮箱" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil, nil nil];  
        [alert show];  
    }  
}  

 

邮箱格式要求是:

 

必须包含一个并且只有一个符号@ 

第一个字符不能是'@'或者'.' 

不允许出现'@.'或者'.@'或者'-@'或者'@-' 

结尾不得是字符'@'或者'.' 

字符@后面只能是'A-Za-z0-9' 

 

 

 

 

你可能感兴趣的:(jquery+js教程)