Solved

Validate domain name

Posted on 2011-09-15
16
390 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

635 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