maztt
maztt

Reputation: 12294

Regular expression to check for a URL's protocol

Currently using:

@"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$

How can i make http:// not compulsory but if it does exist, it must be written as http://

Upvotes: 6

Views: 9952

Answers (1)

Jens
Jens

Reputation: 25563

Replace

^(ht|f)tp(s?)\:\/\/

by

^(?:(ht|f)tp(s?)\:\/\/)?

Upvotes: 15

Related Questions