Skip to content

Commit e1756d9

Browse files
committedMar 7, 2025
Add email regex
1 parent 8341e78 commit e1756d9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎apple/InlineIOS/Onboarding/Email.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ struct Email: View {
7474
}
7575
}
7676

77+
private let emailRegex = #"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"#
78+
7779
private func validateInput() {
7880
errorMsg = ""
79-
isInputValid = !email.isEmpty && email.contains("@") && email.contains(".")
81+
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex)
82+
isInputValid = !email.isEmpty && emailPredicate.evaluate(with: email)
8083
}
8184

8285
func submit() {

0 commit comments

Comments
 (0)