2

I am trying to create a email address regular expression that only accepts emails address ending with "@gbase.tt".

I tried: ^[A-Z0-9._%+-]+@gbase\.tt$

3
  • Yours is ok, you just lack the lowercase chars and escaping the . at the domain: ^[a-zA-Z0-9._%+-]+@gbase\.tt$ - regexr.com?35qhk - But you really should use a tool, as your language probably already has it. Commented Aug 2, 2013 at 20:06
  • 1
    Don't validate email addresses with regular expressions: davidcel.is/blog/2012/09/06/… Commented Aug 2, 2013 at 20:09
  • Yes, don't validate email addresses with regular expressions. The ones that are close to matching all valid cases are overcomplicated and they still don't work as they should be. Commented Aug 3, 2013 at 1:06

4 Answers 4

5

Why use a regular expression when you can test if the string ends with "@gbase.tt"?

But if you really must use a regex, try ^[email protected]$.

Sign up to request clarification or add additional context in comments.

1 Comment

I honestly didn't think of testing if the string ends with "@gbase.tt" at first was just editing some code and I wanted to change my previous regular expression to do what I stated above.
2

I'd start with a full regex for email, like the one found here.

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) 

That expression clearly has the @ split in it, so keep the first half, and replace everything after the @ sign with gbase\.tt$.

Keep in mind that you've got to escape the dot since a dot by itself represents any character.

Comments

0
 var x=document.forms["myForm"]["emailId"].value; var atpos=x.indexOf("@abc.com"); var atpos1=x.indexOf("@xyz.in"); var atpos2=x.indexOf("@www.in"); if (atpos<1 && atpos1<1 && atpos2<1) { alert("Not a valid e-mail address"); return false; } 

Comments

0

Here is the solution for fixed domain name and email id containing "." or "_"

you can use pattern - pattern="^[A-Za-z0-9]+(.|_)+[A-Za-z0-9]+@+gmail.com$"

it will only accept email id with domain name gmail.com only

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.