1

I need an regular expression which accept 10 digit phone number and also email address with one input textfield.

Example :

Phonenumber: 1234567890

Emailaddress : somename@somecompany.com or somename@somecompany.in

Can any one advice me to get that regular expression. @KiranMac123

KkMIW
  • 1,092
  • 1
  • 17
  • 27

2 Answers2

1

Use the below regex to match the 10 digit phone number or an email address.

^(?:\d{10}|\w+@\w+\.\w{2,3})$
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • 1
    `\w+@\w+\.\w{2,3}` is nowhere close to good enough to match all valid email addresses. See http://stackoverflow.com/a/201378/9530 for why. – Adam Rosenfield Nov 08 '14 at 06:22
0

I would simply do this:

^(.+@.+|\d{10})$

Note that this regex does not match all valid email addresses. And it does match some that are not valid. But for most cases it's good enough.

Unless you have a good reason, I would strongly advice against using a regex to check email addresses. Read here why

klutt
  • 30,332
  • 17
  • 55
  • 95