0

I'm Following the below Example:

Email validation expression \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* allows empty spaces

I'm using EMAIL_PATTERN:

 `/^(\w+([.]\w+)*@\w+([.]\w+)*\.\w+([.]\w+)*)$/`

with minor changes. It is allowing me to enter the email as i want but i dont want "_" at the starting of the email address. Example: _abc@gmail.com How to solve this? What regex google is using in gmail?

Community
  • 1
  • 1
DirtyMind
  • 2,353
  • 2
  • 22
  • 43
  • 1
    `\w` is equal to `[a-zA-Z0-9_]`, so switch it out with a character class instead and remove the underscore. Keep in mind that your regex allows for an email that starts with an at sign (since the entire group before the at sign is `*`. – h2ooooooo Sep 25 '15 at 06:16
  • 4
    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) – Marty Sep 25 '15 at 06:17
  • 1
    Read this http://www.regular-expressions.info/email.html about validating email via regex. It is very comprehensive. BTW an email could start with `_`. – RedX Sep 25 '15 at 06:21
  • What language are you writing this in? You're much better off using an email validation library. For example, [Email::Valid](https://metacpan.org/pod/Email::Valid) in Perl. – Schwern Sep 25 '15 at 06:23
  • I am using angular js. I have updated it like below as mentioned by h200000: /^(\[a-zA-Z0-9]+([.]\[a-zA-Z0-9]+)*@\w+([.]\w+)*\.\w+([.]\w+)*)$/ is it correct?? I trid this but its not working. – DirtyMind Sep 25 '15 at 06:26
  • possible duplicate of [Validate email address in JavaScript?](http://stackoverflow.com/questions/46155/validate-email-address-in-javascript) – Schwern Sep 25 '15 at 06:30
  • The [validator regex in Parsley.js](https://github.com/guillaumepotier/Parsley.js/blob/master/src/parsley/validator_registry.js) is one of the better I've seen in Javascript. – Schwern Sep 25 '15 at 06:40
  • http://stackoverflow.com/users/247893/h2ooooooo i changed \w with below: /^([a-zA-Z0-9]+([.][a-zA-Z0-9]+)*@\w+([.]\w+)*\.\w+([.]\w+)*)$/ is it correct or not?? – DirtyMind Sep 25 '15 at 06:50
  • stackoverflow.com/users/247893/h2ooooooo Thanks !! it is working as per my requirements now. – DirtyMind Sep 25 '15 at 06:54

1 Answers1

-1

Use This

/^([a-zA-Z0-9]+([.][a-zA-Z0-9]+)@\w+([.]\w+)\.\w+([.]\w+)*)$/,