s.webbandit
s.webbandit

Reputation: 17000

How to allow string both to match certain expression and not to contain another string

I have a telephone number checking regex:

/^\+\d{1,3}[\d ]*$/ (it matches +7 5165761074).

I need this regexp also not to allow 0000000 and 1234567 inside.

Upvotes: 0

Views: 45

Answers (1)

Udo Klein
Udo Klein

Reputation: 6882

You could use negative lookahead

/^\+(?!0000000)(?!1234567)\d{1,3}[\d ]*$/

http://www.javascriptkit.com/javatutors/redev2.shtml

The actual expression in the lookaheads might be slightly different depending on what exactly you mean with "not allow inside".

Upvotes: 3

Related Questions