Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Validate domain name

Posted on 2011-09-15
16
Medium Priority
?
401 Views
Last Modified: 2012-05-12
I allow the user enter the domain name and i do not want them to enter
like http://, or www, so what i need is test.com
basically  cgi.server_name
0
Comment
Question by:erikTsomik
  • 7
  • 5
  • 4
16 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36545484
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36545529
well it looks good but I need to ignore any http://,www. All I will allow user to enter ois the domain name test.com
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36545542
then try this

/^[a-z0-9](?:[a-z0-9-]?[a-z0-9])*\.[a-z\.]{2,6}$/i;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Author Comment

by:erikTsomik
ID: 36545691
it works fine accpet for one piece.

It I enter http://test.com it fail which is good
I enter www.test2.com fails which is fine

But what if enter mysite.test.com it fails but i need it to pass
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36545720
try this..
/^[a-z0-9\.](?:[a-z0-9-]?[a-z0-9])*\.[a-z\.]{2,6}$/i;
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36545735
it does not work it does not allow the dot
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36545741
what about : /^[a-z0-9_-]*\.[a-z0-9_]*$/i
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36545751
fails
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36545753
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36545764
if you do this  it pass
result = /^[a-z0-9_-]*\.[a-z0-9_]*$/i.test(".google.com");
alert(result);

but if you run this it  fails
result = /^[a-z0-9_-]*\.[a-z0-9_]*$/i.test("test.google.com");
alert(result);
0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 2000 total points
ID: 36545766
>fails

with?

I get "true" only on the last on in the test page (a new one with cgi.server_name) : http://jsfiddle.net/H5C4A/2/
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36545790
it works in the sample by in my code this one test.test.com fails
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36545818
sorry.. try this..
/^[a-z0-9](?:[a-z0-9-]?[a-z0-9\.])*\.[a-z\.]{2,6}$/i;
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36545858
another one : /^((?!www\.)(?!http:\/\/))([a-z0-9_-]+\.)+[a-z0-9_]+$/i
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36545867
0
 
LVL 19

Author Closing Comment

by:erikTsomik
ID: 36545980
thank you .Great
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question