0

I want that form submit when user enter their domain without https:// or http:// or / at the end.what is the regular expression for this.

https://google.com   wrong
http://google.com    wrong
google.com           correct
subdomain.google.com correct
google.com/          wrong

Please tell me what is the regular expression for this

user3262732
  • 240
  • 1
  • 4
  • 15

3 Answers3

3
^(?!https?:\/\/)\w+(\.\w+)+$

You can try this.See demo.

http://regex101.com/r/oE6jJ1/41

^(?!https?:\/\/)(?!.*?\/$)[\w./]+$

You can try this is you have inputs like google.com/something.See demo.

http://regex101.com/r/oE6jJ1/40

vks
  • 67,027
  • 10
  • 91
  • 124
  • 2
    Just `^[\w.]+$` would do the same thing. – Ja͢ck Nov 27 '14 at 04:21
  • will you please tell me why i am getting `-1` when using your expression [here](http://jsfiddle.net/axtruo/r350ck2t/) – user3262732 Nov 27 '14 at 04:29
  • @user3262732 try putting it in a delimiter.`/^(?!https?://)\w+(\.\w+)+$/` – vks Nov 27 '14 at 04:33
  • one last thing what if i checked that string not contain `/` at the start or end of a simple string – user3262732 Nov 27 '14 at 04:38
  • @user3262732 the regex wont allow `/` at the start or end.You can try in the demo. – vks Nov 27 '14 at 04:40
  • this is work fine . thanks for the help but now i want to validate another input field. that field contain `foldername` and i want to test the input will never contain `/` at the start or at the end of the string – user3262732 Nov 27 '14 at 04:44
  • @user3262732 it would be better if you can ask a new question as we will have to modify the accepted answer.any ways try `\w+(/\w+)*` – vks Nov 27 '14 at 04:47
0

Instead of @vks's answer, I would do the more simple: ^[\w.]+\.[a-z]+$. This makes sure that has a word, and that there is a period "." and then a few more lowercase letters.

I hope that helps!

Ian Hazzard
  • 7,661
  • 7
  • 34
  • 60
0

What you want is a "fully qualified domain name" (FQDN), not a URL. FQDN regexp is the following (from this answer):

(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)

Simpler regular expressions can result in FQDNs that violate the RFC, by being too long, by allowing disallowed characters, or characters in disallowed positions (e.g. -.-, a..a or __.com would be matched my some of the other suggestions on this page, while not being valid FQDNs).

Community
  • 1
  • 1
Amadan
  • 191,408
  • 23
  • 240
  • 301