Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

Validate domain name

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
erikTsomik
Asked:
erikTsomik
  • 7
  • 5
  • 4
2 Solutions
 
ansudhindraCommented:
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
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
 
ansudhindraCommented:
then try this

/^[a-z0-9](?:[a-z0-9-]?[a-z0-9])*\.[a-z\.]{2,6}$/i;
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
erikTsomikSystem Architect, CF programmer Author Commented:
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
 
ansudhindraCommented:
try this..
/^[a-z0-9\.](?:[a-z0-9-]?[a-z0-9])*\.[a-z\.]{2,6}$/i;
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
it does not work it does not allow the dot
0
 
leakim971PluritechnicianCommented:
what about : /^[a-z0-9_-]*\.[a-z0-9_]*$/i
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
fails
0
 
leakim971PluritechnicianCommented:
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
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
 
leakim971PluritechnicianCommented:
>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
 
erikTsomikSystem Architect, CF programmer Author Commented:
it works in the sample by in my code this one test.test.com fails
0
 
ansudhindraCommented:
sorry.. try this..
/^[a-z0-9](?:[a-z0-9-]?[a-z0-9\.])*\.[a-z\.]{2,6}$/i;
0
 
leakim971PluritechnicianCommented:
another one : /^((?!www\.)(?!http:\/\/))([a-z0-9_-]+\.)+[a-z0-9_]+$/i
0
 
leakim971PluritechnicianCommented:
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
thank you .Great
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now