English 中文(简体)
是否有办法使文本外地条目必须是电子邮件? (xcode)
原标题:is there any way to make a Text field entry must be email? (in xcode)

I want to make a user login form and it needs to use emails not just usernames. Is there any way i can make a alert pop up if it is not an email? btw All of this is in xcode.

最佳回答
问题回答

为了以现代法典不断更新这一员额,我认为,把快速答案张贴在akashivskyy s原始客观的答复中是明智的。

// MARK: Validate
func isValidEmail(email2Test:String) -> Bool {
    let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}"
    let range = email2Test.rangeOfString(emailRegEx, options:.RegularExpressionSearch)
    let result = range != nil ? true : false
    return result
}    

我在我的发言中做了类似的事情,我证实,电子邮件地址现场有两部分用“@文号分开,至少有两部分用文号分开。 这并不阻止它是一个有效的电子邮件地址,但确实确保它至少是正确的格式。 守则例:

// to validate email address, just checks for @ and . separators
NSArray *validateAtSymbol = [[emailRegisterTextField text] componentsSeparatedByString:@"@"];
NSArray *validateDotSymbol = [[emailRegisterTextField text] componentsSeparatedByString:@"."];

// checks to make sure entries are good (email valid, username available, passwords enough chars, passwords match
if ([passwordRegisterTextField text].length >= 8 &&
    [passwordRegisterTextField text].length > 0 &&
    [[passwordRegisterTextField text] isEqual:[passwordVerifyRegisterTextField text]] &&
    ![currentUser.userExist boolValue] &&
    ![[emailRegisterTextField text] isEqualToString:@""] &&
    ([validateAtSymbol count] == 2) &&
    ([validateDotSymbol count] >= 2)) {

// get user input
NSString *inputEmail = [emailRegisterTextField text];
NSString *inputUsername = [userNameRegisterTextField text];
NSString *inputPassword = [passwordRegisterTextField text];
NSString *inputPasswordVerify = [passwordVerifyRegisterTextField text];

NSLog(@"inputEmail: %@",inputEmail);
NSLog(@"inputUsername: %@",inputUsername);
NSLog(@"inputPassword: %@",inputPassword);
NSLog(@"inputPasswordVerify: %@",inputPasswordVerify);

// attempt create
[currentUser createUser:inputEmail username:inputUsername password:inputPassword passwordVerify:inputPasswordVerify];
}
else {
    NSLog(@"error");
    [errorLabel setText:@"Invalid entry, please recheck"];
}

如果情况不正确,你可以发出警示,但我选择用错误信息显示<条码>:Label/code>,因为对使用者来说,这种警示似乎不太jar。 在上述法典中,我检查了电子邮件地址的格式、密码长度以及密码(两次送交核查)。 如果所有测试都未能通过,则评估者没有采取行动。 你可以选择你想要证实的哪一个领域。

This way works well for me.

1.check string has only one @

2. 至少检查一次。 页: 1

2. 在“......”之后,在任何空位内

-(BOOL)checkEmailString :(NSString*)email{
//DLog(@"checkEmailString = %@",email);
BOOL emailFlg = NO;
NSArray *atArr = [email componentsSeparatedByString:@"@"];

//check with one @
if ([atArr count] == 2) {
    NSArray *dotArr = [atArr[1] componentsSeparatedByString:@"."];

    //check with at least one .
    if ([dotArr count] >= 2) {
        emailFlg = YES;

        //all section can t be
        for (int i = 0; i<[dotArr count]; i++) {

            if ([dotArr[i] length] == 0 ||
                [dotArr[i] rangeOfString:@" "].location != NSNotFound) {
                emailFlg = NO;
            }
        }
    }
}

return emailFlg;
}




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签