Solved

Validate domain name

Posted on 2011-09-15
16
375 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 82

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 82

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 82

Assisted Solution

by:leakim971
leakim971 earned 500 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 82

Expert Comment

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

Accepted Solution

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

Author Closing Comment

by:erikTsomik
ID: 36545980
thank you .Great
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

831 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