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
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
0
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ansudhindraCommented:
then try this

/^[a-z0-9](?:[a-z0-9-]?[a-z0-9])*\.[a-z\.]{2,6}$/i;
0
 
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
 
leakim971Connect With a Mentor PluritechnicianCommented:
>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
 
erikTsomikSystem Architect, CF programmer Author Commented:
thank you .Great
0
All Courses

From novice to tech pro — start learning today.