Reputation: 11403
Q: I want a regular expression to validate the URL but i wanna to allow this character(~)the Tilda
something like this url:
http://stackoverflow.com/questions/~/
allowing http
or without http
thanks in advance
EDIT:
i find a perfect one finally:
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
but i wanna to allow the user to enter the url with the protocol or without it to prevent any confusion how to do that.
Upvotes: 2
Views: 2079
Reputation: 5201
There is a very good regular expressions site here where you can get almost any regular expressions. Think this would be useful to you.
Upvotes: 1
Reputation: 8561
I'm not sure what do u want. But
\w+([~'\.]\w+)+
Valid for
justname'com
just_name~com
justname.com
Invalid for
justname
just-name-com
If you use
\w+([~]?)\w+\.\w+
Valid for
justname.com
just~name.com
Invalid for
justname'com
just_name~com
just-name-com
Upvotes: 1
Reputation: 169143
To allow non-consecutive tildes:
\w+([-+.'~]\w+)*
To allow tildes anywhere:
[\w~]+([-+.'][\w~]+)*
Upvotes: 2
Reputation: 10337
you can try with this one:
\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]
if you don't need the HTTP,FTP... youc an take it off like:
\b[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]
Regards, HTH.
Upvotes: 1