-1

I found this code in google:

func isEmail(email: String) -> Bool {
    let emailRegx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
     
     let emailTest = NSPredicate(format: "SELF MATCHES %@", emailRegx)
     
     return emailTest.evaluate(with: email)
    }

but I want to change the emailRegx to ensure that the first two characters in an email address can not be a number or symbols

AMANI
  • 11
  • 2
  • `the first two characters in an email address can not be a number or symbols`, can you provide an example of how a email address should look like to pass the check (and how it shouldn't)? it's not clear what an email needs to start with if neither number nor symbol is acceptable. – The Dreams Wind Jul 28 '22 at 15:06
  • Thanks for adding additional information. if you combine your added code with that from my answer, do you get the desired result? – de. Jul 28 '22 at 22:31

1 Answers1

1

Your question is not very specific and lacks details or some code that you have tried.
However, this is my take based on how I understood your issue:

import Foundation

var validMail = "foo@bar.com"
var invalidMail = "1foo@bar.com"

func validateFirstLetter(_ string: String) -> Bool {
    string.first?.isLetter == true
}

print( validateFirstLetter(validMail) )   // true
print( validateFirstLetter(invalidMail) ) // false

For proper email validation you will find many implementations with a simple google search. For example:
How to validate an e-mail address in swift?

de.
  • 7,068
  • 3
  • 40
  • 69