-2

Just started out with regex and struggling to find the right expression. It should contain one "@" character and before and after the "@" it should contain at least one and at most 64 chars which are letters/numbers or dots.

valid: mark@mail.com 
valid: .@. 
invalid: @example.com

I tried: ([a-zA-Z]+\d+\b.@.\b[a-zA-Z]+\d+) don't get how you mark a character optional. What regex would work?

Update: I tried that suggestion ie other solution , did not work for me : (

bier hier
  • 20,970
  • 42
  • 97
  • 166
  • 5
    Possible duplicate of [How to validate email address in JavaScript?](https://stackoverflow.com/questions/46155/how-to-validate-email-address-in-javascript) – Nir Alfasi Dec 12 '17 at 04:22
  • @alfasin not working for me unfortunately – bier hier Dec 12 '17 at 04:26
  • 1
    "not working for me" is not helpful. Post what did you try, which input you ran on, what was the result vs. what is the expected result. You have enough rep to know that – Nir Alfasi Dec 12 '17 at 04:28

1 Answers1

2

You can use the below regex to match email id.

var emailValidation = function(str){
  return /^[a-zA-Z\d\.]{1,64}@[a-zA-Z\.\d]{1,64}$/.test(str);
}

console.log(emailValidation('mark@mail.com'));
console.log(emailValidation('.@.'));
console.log(emailValidation('@example.com'));
Hassan Imam
  • 21,956
  • 5
  • 41
  • 51