-1
登録を厳密に.eduに制限する機能を作成しようとしています。 .eduのサインアップをしている限り、どの大学の学生もサインアップできる機能を実装するにはどうすればよいですか。私はFacebook登録機能を持っていますが、その後、ユーザーを電子メールの確認画面にリダイレクトしたいと思います。iPhoneアプリケーションで.edu電子メールの確認を追加するには?
func validate(email: String) -> Bool {
do {
//instantiate a regex checking for valid email ending in .edu
let regex = try NSRegularExpression(pattern: "^[a-zA-Z0-9._%+-][email protected][a-zA-Z0-9.+-]+\.edu$", options: NSRegularExpression.Options.caseInsensitive)
//get the number of matches
let matches = regex.matches(in: email, options: [], range: NSRange(location: 0, length: email.characters.count))
//if no matches, then email provided does not meet your requirements - otherwise the email validates
return matches.count > 0
} catch { //regular expression init failed...
return false
}
}
//conform EmailConfirmationVC UITextFieldDelegate class EmailConfirmationVC: BaseTableVC, UITextFieldDelegate {
//set up your IBOutlets and other properties as you have already, avatar, nameValue, gener, etc -
@IBOutlet weak var emailTF: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
//set your email textfield delegate to self
emailTF.delegate = self
//the rest of your viewDidLoad...
}
//add the validate func above as a method of this class
func validate(email: String) -> Bool { //etc
}
//then implement the textFieldDidEndEditing
func textFieldDidEndEditing(_ textField: UITextField) {
//for now, we are only interested in your email field - so if its not, return early
if textField != emailTF { return }
//else, safely unwrap and use the text from the field
guard let userEmail = textField.text else { return }
//then you the validate method to verify the email checks out
let validEduEmail = validate(email: userEmail)
if validEduEmail {
//email is a valid .edu email -> move on to next registration steps, etc
} else {
//otherwise - this is not an .edu email - let the user know somehow
}
}
あなたは、サインアップボタンがタップされたときに、電子メールテキストフィールドに ".edu"で終わるテキストがあることを確認したいですか? –
ええと私はユーザーにも自分の電子メールを確認してほしい。 –