Mohan Krishnan
Mohan Krishnan

Reputation: 353

Regex - Does not starts with but contains

I have created a regex to match a phone number using the following one:

^[+0-9():.]+$

But this regex matches a number that starts with a dot too. My usecase is to modify the above regex such that it matches a number that doesnt starts with a dot but contians a dot.

Upvotes: 1

Views: 1626

Answers (2)

roeygol
roeygol

Reputation: 5028

Try using this regex:

(^(?![.])[+0-9():.]+$)

You can also specify how many numbers you need in the second part of the regex

Upvotes: 2

vks
vks

Reputation: 67968

^(?![.])[+0-9():.]+$

you can simply add a lookahead.

Upvotes: 1

Related Questions