Jump to content

help!! validate a domain


SetLar8

Recommended Posts

Hi,

 

I currently have a form that requires the user to enter a domain and then select the extension from a list.

 

e.g.

 

domain = phpfreaks

extension = .com

 

I have been trying for over a day to create an ereg statement for this but just cannot do it.

 

I need the ereg statment to check for following in the domain variable

 

1. A Domain Name can contain only English letters "a-z", numbers "0-9" and a hyphen "-".

2. The domain name must start and end with a letter or a number. Hyphens can not be located at the end or the beginning of a name.

3. You can not use spaces.

4. A domain name is not case sensitive.

 

If anyone can help me with this i would be very greatful, also if you can point me to a site for beginners of ereg statements. I would say my general php programming level is advanced but i cannot get my head around ereg.

 

Thanks.

Link to comment
Share on other sites

Hi,

 

I have just been playing around with this and have come up with this statement which seems to work:

 

eregi("([a-z0-9-]+)$", $domain)

 

Can someone tell me how the "()", "[]", "+" and "$" are affecting this.

 

Thanks.

Link to comment
Share on other sites

Hmm, why don't you use: gethostbyname('www.example.com');

It returns the ip of a website and when the website doesn't exists, it returns an IP that is the same for every other false website.

 

Hope this is usefull

 

Grtz

 

// EDIT

 

Sorry I realised I missunderstood... Probably you don't want to check for the existence of a domain...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.