Tom
Tom

Reputation: 12998

Validation Expression to allow email or 10 digit number

I have two validation scripts which work in their own right, but I now want to make a text box validate the content to either be one or the other - in this case an email address or a 10 digit number.

I have the following...

^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$

^[a-zA-Z0-9]{1,10}$

I want to merge these into a single either/or validation expression.

Upvotes: 0

Views: 690

Answers (1)

Davide
Davide

Reputation: 2339

You can join two or more regex with the | "or" operator

^([a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]|[a-zA-Z0-9]{1,10})$

Check a test here

Upvotes: 1

Related Questions