如何确保我的电子邮件字段的文字以@ companyname.com结尾 所以如果它以@ gmail.com之类的东西结束呢?
@IBAction func login(_ sender: Any) {
if self.emailField.text != "" || self.passwordField.text != "" && self.emailField.text == //what do i put here?//
{
}
}
答案 0 :(得分:0)
一种选择是使用hasSuffix(:)
检查特定后缀。
@IBAction func login(_ sender: Any) {
if self.emailField.text != "" || self.passwordField.text != "" && self.emailField.text.hasSuffix("@companyname.com")
{
}
}