0

I am trying to create a Pattern to Validate Domain Name without "http://www" , but I am unable to do so Completely please someone help me;

"\\.[a-zA-Z][a-zA-Z]"
".*?([^.]+\\.[^.]+)"
Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62

4 Answers4

3

Pattern: ^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$

Description
Domain names: This regular expression tests the validity of a domain or hostname. It will match any valid domain name that does not contain characters which are invalid in URLs, and which ends in .com, .org, .net, .mil, or .edu. You can add additional valid TLDs by appending the | (pipe) character and the desired TLD to the list in the parens.

Matches
3SquareBand.com | asp.net | army.mil

For more patterns check here

Hip Hip Array
  • 4,665
  • 11
  • 49
  • 80
3

Have you tried patterns from class Patterns ?

Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
  • 1
    will you please help me to use this – Krishnakant Dalal Jun 01 '12 at 09:40
  • in package android.util is Patterns class which contains some patterns: TOP_LEVEL_DOMAIN_STR Regular expression to match all IANA top-level domains. TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL Regular expression to match all IANA top-level domains for WEB_URL. TOP_LEVEL_DOMAIN Regular expression pattern to match all IANA top-level domains. WEB_URL Regular expression pattern to match most part of RFC 3987 Internationalized URLs, aka IRIs. – Buda Gavril Jun 01 '12 at 09:45
  • Yes I read this but not able to use it Please tell me how to use this class – Krishnakant Dalal Jun 01 '12 at 09:49
  • Hey thanks gabi I was using Android 2.1 so I was not able to implement this. Now i can thanks. – Krishnakant Dalal Jun 01 '12 at 10:14
0

That Pattern API is not perfect in my case so I used this Regular Expression.

Pattern p = Pattern.compile("^(http|ftp|https)://|^[a-zA-Z0-9]+\\.[a-zA-Z][a-zA-Z]" );
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
0

For Java developers, this pattern works for my problem:

private static final String DOMAIN_START_END_PATTERN_STRING =
    "^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,65}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}$";
t0mm13b
  • 34,087
  • 8
  • 78
  • 110
Frost
  • 1