0

I wonder if anyone could make a suggestion how i achieve the following?

I have a regex which suffices in the validation of email addresses which is as follows:

^(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)*$ 

Its a loose validator but as i said, it suffices for what we need. What I need to do if possible is validate on the following criteria:

1) validate email addresses based on the above format 2) if not an email address as above, check if value is N/A or n/a

Appreciate anyones help,

Thanks

Jon

Jon Selby
  • 502
  • 1
  • 8
  • 23
  • 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) – Rinke Nov 26 '13 at 09:40
  • validating an email address was not the problem outlined here, the problem was that I had not even considered the or operator in allowing for varying patterns. – Jon Selby Nov 26 '13 at 12:33

2 Answers2

1

With little modifications to your original expression you can acheive what you wanted... You can use Or operator to match multiple patterns. (PatternA)|(PatternB)|(PatternC) will match for all three patterns A, B & C. So, below should work.

((\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b))|(N/A)|(n/a)

Or the below should also work

([\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6})|(N/A)|(n/a)

Source: http://RegExr.com?3563b

Buddha
  • 4,339
  • 2
  • 27
  • 51
0

You can try this regex:

^(\b[Nn]\/[Aa]|(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})\b)$ 
anubhava
  • 761,203
  • 64
  • 569
  • 643