Andrew Fletcher published: 15 July 2020 (updated) 28 December 2020 1 minute read
I'm currently working on a project that requires login, register, forget password functionality in SwiftUI. As I'm developing the code, I came across a great resource for validating an email address with Regex:
In the end, I leveraged the worked produced on https://stackoverflow.com/questions/25471114/how-to-validate-an-e-mail-address-in-swift
The code used:
extension String { var isValidEmail: Bool { let name = "[A-Z0-9a-z]([A-Z0-9a-z._%+-]{0,30}[A-Z0-9a-z])?" let domain = "([A-Z0-9a-z]([A-Z0-9a-z-]{0,30}[A-Z0-9a-z])?\\.){1,5}" let emailRegEx = name + "@" + domain + "[A-Za-z]{2,8}" let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegEx) return emailPredicate.evaluate(with: self) } }
Related articles
Andrew Fletcher
•
17 Dec 2023
Ignoring ffi-1.16.3 because its extensions are not built. Try: gem pristine ffi --version 1.16.3
The error you're encountering indicates an issue with the ffi gem during the CocoaPods update. The error message suggests trying to run the gem pristine command to fix it.Using terminal - run the following command:gem pristine ffi --version 1.16.3This command will attempt to restore the ffi gem to...
Andrew Fletcher
•
16 Apr 2023
Xcode: Non-constant range: argument must be an integer literal error
Creating a foreach loop such as
var maxDigits: Int = 5
private var pinDots: some View {
HStack {
ForEach(0..<maxDigits) { index in
ZStack {
Image(systemName: self.getImageName(at: index))
.font(.system(size: 50.0, weight: .thin,...
Andrew Fletcher
•
12 Aug 2022
Using SwiftUI URLComponent to change a URL's scheme
The challenge I was facing, I had written a script to scan barcodes and use Google book API to view the contents. However, a snippet of the JSON response
{
"contentVersion": "0.2.0.0.preview.0",
"panelizationSummary": {
"containsEpubBubbles": false,
...