SetLar8 Posted April 29, 2007 Share Posted April 29, 2007 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 https://forums.phpfreaks.com/topic/49195-help-validate-a-domain/ Share on other sites More sharing options...
SetLar8 Posted April 29, 2007 Author Share Posted April 29, 2007 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 https://forums.phpfreaks.com/topic/49195-help-validate-a-domain/#findComment-241063 Share on other sites More sharing options...
per1os Posted April 29, 2007 Share Posted April 29, 2007 http://www.regular-expressions.info/tutorial.html www.php.net/regex http://en.wikipedia.org/wiki/regex Plenty of resources out there. Link to comment https://forums.phpfreaks.com/topic/49195-help-validate-a-domain/#findComment-241118 Share on other sites More sharing options...
jscix Posted April 29, 2007 Share Posted April 29, 2007 regex is a mysterious language created by aliens, imo. I'll never understand it, no matter how much I read ::oo Link to comment https://forums.phpfreaks.com/topic/49195-help-validate-a-domain/#findComment-241225 Share on other sites More sharing options...
Intelly XAD Posted April 29, 2007 Share Posted April 29, 2007 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 https://forums.phpfreaks.com/topic/49195-help-validate-a-domain/#findComment-241265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.