0

Is there any way to make Custom own email regular expression?

Actually I want to create one registration form in p.h.p. and for email validation,

I want to make my own customized email regular expression. For example,lets say I want to check that the given mail is name-number@ves.ac.in.

It should only accept email id that ends with ves.ac.in and should notify if given mail is not matching with expression. I did lot of experiment on:

^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$

but this expression but failed. please help.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
akshay
  • 27
  • 1
  • 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) – gyre Dec 07 '16 at 06:19
  • The regex that you show appears to (try to) validate generic email addresses, it doesn't restrict to `ves.ac.in`. You want to start with something like `^([a-zA-Z0-9_\-\.]+)@ves\.ac\.in$`. – nnnnnn Dec 07 '16 at 06:20
  • `^([a-zA-Z0-9_\-\.]+)@ves\.ac\.in$` – bansi Dec 07 '16 at 06:22

3 Answers3

1

The right regex could be this: ^([a-zA-Z0-9_\-\.]+)@ves\.ac\.in$

Here's a regex-tester

Patrick Mlr
  • 2,955
  • 2
  • 16
  • 25
0

if you are validating with jQuery or javascript, then you can validate using

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if(!filter.test(email)){
 // add error here
}
rushil
  • 591
  • 7
  • 16
-1

To check for a particular domain e.g, (yahoo.com):

 regx =  /^[^@\s]+@yahoo\.com$/i;
 regx.test(input);
 //returns true if it matches

check this fiddle here.

shibli049
  • 528
  • 12
  • 31
Raki
  • 535
  • 4
  • 13
  • you can put your own domain. – Raki Dec 07 '16 at 11:40
  • I didn't point out about any domain. the `dot` in your regular expression matches any character not a literal `.` you should escape it like `^[^@\s]+@yahoo\.com$` – bansi Dec 07 '16 at 11:43