Solved

Validate domain name

Posted on 2011-09-15
16
373 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
Comment Utility
0
 
LVL 19

Author Comment

by:erikTsomik
Comment Utility
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
Comment Utility
then try this

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

Author Comment

by:erikTsomik
Comment Utility
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
Comment Utility
try this..
/^[a-z0-9\.](?:[a-z0-9-]?[a-z0-9])*\.[a-z\.]{2,6}$/i;
0
 
LVL 19

Author Comment

by:erikTsomik
Comment Utility
it does not work it does not allow the dot
0
 
LVL 82

Expert Comment

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

Author Comment

by:erikTsomik
Comment Utility
fails
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Expert Comment

by:leakim971
Comment Utility
0
 
LVL 19

Author Comment

by:erikTsomik
Comment Utility
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
Comment Utility
>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
Comment Utility
it works in the sample by in my code this one test.test.com fails
0
 
LVL 13

Expert Comment

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

Expert Comment

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

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
0
 
LVL 19

Author Closing Comment

by:erikTsomik
Comment Utility
thank you .Great
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Linux Scripting 3 39
User profile Size Report 3 35
Remove Protocol if at start of string? 3 11
Cordova Camera plugin fails 2 12
I recently found myself in a Corporate Situation where the client had requested blocking access to any and all websites except his own Domain? Easy? I am sure this would be your answer but their requirement was, this has to be done without using…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
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)
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now