Steve
Steve

Reputation: 229

Regular Expression with specific criteria

Hey everyone, I'm trying to type a regular expression that follows the following format:

[email protected] or [email protected]

There are no special characters or numbers permitted for this criteria. I thought I had it down, but I'm a bit rusty with regular expressions and when I tested mine, it failed all across the boards. So far, my regular is expression is:

^[a-zA-Z]+/.?[a-zA-Z]*@[a-zA-Z]+/.?[a-zA-Z]*/.com$

If anyone could help me, it would greatly be appreciated, thanks.

Upvotes: 0

Views: 124

Answers (3)

Sören
Sören

Reputation: 2731

your regex looks good. I think you need to change the / to \ in front of the . . Additionally, if you don't want [email protected] pass your regex, u should change your regex to

^[a-zA-Z]+(\.[a-zA-Z]+)?@[a-zA-Z]+(\.[a-zA-Z]+)?\.com$

(not completely sure about the brackets () though, but i think that should be working)

Upvotes: 1

Meitham
Meitham

Reputation: 9670

its a backslash to espace dots. Also put the the parenthesis around the . and what follows otherwise an email like [email protected] would be valid.

^[a-zA-Z]+(\.[a-zA-Z]+)?@[a-zA-Z]+(\.[a-zA-Z]+)?\.com$

Upvotes: 1

Jon
Jon

Reputation: 16728

It looks mostly OK. Change your / to \ though...

For the second case, I would ensure that if you have a . in the middle, it must be followed by more letters:

^[a-zA-Z]+(\.[a-zA-Z]+)?@[a-zA-Z]+(\.[a-zA-Z]+)?\.com$

Upvotes: 0

Related Questions