Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created March 15, 2020 16:00
Show Gist options
  • Save foxicode/2d8e8f00be79aac861c64a619aaa7372 to your computer and use it in GitHub Desktop.
Save foxicode/2d8e8f00be79aac861c64a619aaa7372 to your computer and use it in GitHub Desktop.

Revisions

  1. foxicode created this gist Mar 15, 2020.
    13 changes: 13 additions & 0 deletions String+isEmailValid2.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    extension String {
    func matches(_ expression: String) -> Bool {
    if let range = range(of: expression, options: .regularExpression, range: nil, locale: nil) {
    return range.lowerBound == startIndex && range.upperBound == endIndex
    } else {
    return false
    }
    }

    var isValidEmail: Bool {
    matches("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}")
    }
    }