-3

I currently have this in an old system I'm working on:

/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/

It's checking for usernames. I've imported a few email address as username, and these accounts cannot be validated.

How can I modify the above to allow for email addresses? Thanks.

  • 1
    Which valid usernames are not accepted? As far as I see, `@` and `.` are at least missing. Oh, and nowadays there are umlaut domains as well, basically allowing nearly all Unicode characters. – Shi Jul 13 '13 at 20:27
  • 'email@address.com', for example, will not validate and log in. But I trim the same account to just 'email', it logs in no prob. – Shannon Hollingsworth Jul 13 '13 at 20:28
  • possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Shi Jul 13 '13 at 20:39

1 Answers1

1

You can use /^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_.@\x7f-\xff]*$/ as regular expression then. However, it does not check whether the email address actually exists, and it allows for syntactical invalid email addresses as well.

As basically all depends on what you define as valid email address, see some references:

Shi
  • 4,178
  • 1
  • 26
  • 31