Shesha
Shesha

Reputation: 2007

Regex for url without containing (http|https|ftp) and containg port number

My url will be like localhost:5557. And I will not allow http:// or https:// or ftp:// in my url.

Also I tried

^(?:!(ftp|http|https):\/\/)?([a-zA-Z0-9]+\.)?[a-zA-Z0-9][a-zA-Z0-9-]+\.[a-zA-Z]{2,6}?$

But I am getting false when adding the port number.

Any suggestions please !

Upvotes: 1

Views: 161

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174826

Negative lookahead must be like (?!..) not (?:!...)

^(?!(ftp|https?):\/\/)([a-zA-Z0-9]+\.)?[a-zA-Z0-9][a-zA-Z0-9-]+\.[a-zA-Z]{2,6}(?::\d{4})?$

Upvotes: 1

Related Questions