Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validate domain name

Posted on 2011-09-15
16
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 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 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 2000 total points
ID: 36545867
0
 
LVL 19

Author Closing Comment

by:erikTsomik
ID: 36545980
thank you .Great
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

704 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