Reputation: 1450
I'm trying to use the ASP.Net Regular Expression Validator to validate a URL field. URL is www.tachibana.co.jp/tokyosys.htm
. Validation expression used is ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"
but this is not working. Is there anything wrong with the Regular expression or URL ?
Rules are as below.
thanks
Upvotes: 0
Views: 5287
Reputation: 326
var re = /(http(s)?:\\)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?/
if (re.test(txt)) {
alert('Valid URL')
}
you can add domain needed in the last field of com,in,org
Upvotes: 0
Reputation: 336378
The problem is that your regex
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
expects the URL to start with http://
or https://
. Also, the dash inside the character class is misplaced.
Edit: Now that you've posted your rules, I suggest this:
^\s*((?:https?://)?(?:[\w-]+\.)+[\w-]+)(/[\w ./?%&=-]*)?\s*$
After a successful match, group 1 will contain the domain, and group 2 will contain the file path, if present.
Upvotes: 3