473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Validate domain name context

Sam
Validate domain name context

Hello , Today I want to make sure from a given text is a domain style
or not.

for example : the domain can be

example.com or example.com.us or example.us so , what is the pattren
to check the given string is a domain style or not?

note that the first text must be at least 2 chars and the second text
may be 2 or 3 chars and the last text must be 2 chars or null.

Thanks,
Sam Shannaq

Jan 27 '07 #1
9 5381
Sam wrote:
Validate domain name context

Hello , Today I want to make sure from a given text is a domain style
or not.

for example : the domain can be

example.com or example.com.us or example.us so , what is the pattren
to check the given string is a domain style or not?

note that the first text must be at least 2 chars and the second text
may be 2 or 3 chars and the last text must be 2 chars or null.

Thanks,
Sam Shannaq
can also be example.info

bill
Jan 27 '07 #2
Sam
yes sure

so any one have the pattren to check?

On Jan 27, 10:17 pm, bill <nob...@spamcop.netwrote:
Sam wrote:
Validate domain name context
Hello , Today I want to make sure from a given text is a domain style
or not.
for example : the domain can be
example.com or example.com.us or example.us so , what is the pattren
to check the given string is a domain style or not?
note that the first text must be at least 2 chars and the second text
may be 2 or 3 chars and the last text must be 2 chars or null.
Thanks,
Sam Shannaqcan also be example.info

bill- Hide quoted text -- Show quoted text -
Jan 27 '07 #3
There's also '.museum' TLD, e.g.

example.museum

Non-national domain names can only have digits, Latin letters and a
dash in them; dash can't be first or last character. So you can begin
with this pattern:

#^(([a-z0-9][-a-z0-9]*?[a-z0-9])\.)+[a-z]{2,6}$#

That will match all valid 3-rd or higher level domain names as well

However, national domain names can have non-ASCII letters.

Best wishes,

Konstantin

On 28 ñÎ×., 02:12, "Sam" <m.shan...@gmail.comwrote:
yes sure

so any one have the pattren to check?

On Jan 27, 10:17 pm, bill <nob...@spamcop.netwrote:
Sam wrote:
Validate domain name context
Hello , Today I want to make sure from a given text is a domain style
or not.
for example : the domain can be
example.com or example.com.us or example.us so , what is the pattren
to check the given string is a domain style or not?
note that the first text must be at least 2 chars and the second text
may be 2 or 3 chars and the last text must be 2 chars or null.
Thanks,
Sam Shannaqcan also be example.info
bill- Hide quoted text -- Show quoted text -
Jan 28 '07 #4
Sam wrote:
so any one have the pattren to check?
Please don't top post.

How sure do you want to be that a domain is real? Do you just want to make
sure that the domain is lexically sane? If so, you want to check that the
domain name has 2 or more components, each of which contains at least two
alphanumeric characters and may contain hyphens, though the hyphen may not
be the first or last character. Each component should terminate with a dot.
Code here:

$domain = 'me.example.net.';

// Note the domain ends with a dot! This is the correct form for
// a fully qualified domain name, even though most people tend to
// leave out the final dot. Including the dot makes the regular
// expression check much easier, so here we want to make sure that
// $domain ends with a dot, and if not add it.
if (!preg_match('/\.$/', $domain)) $domain .= '.';

// Now check if it meets syntax rules.
$domain_ok = preg_match('/^([a-z0-9][a-z0-9\-]*[a-z0-9]\.){2,}$/',
$domain);

This check will allow for a domain like 'foobar.quux.quuux.' even though
it is obviously not a real domain though. To check that it's a real,
registered domain name, which points to a real IP address, we can use
gethostbyname():

// Firstly, do all the above stuff to make sure it it syntactically
// correct. No point wasting network resources calling gethostbyname()
// for a domain that is obviously invalid. Now:

$domain_ok = $domain_ok && !empty(gethostbyname($domain));

// Now $domain_ok is TRUE iff $domain is an Internet host. Yay!

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 28 '07 #5
Three objections:

1. Not all the registered domain names have valid 'A' record. In that
case, gethostbyname() won't return anything meaningful for registered
domain. You'll have to address WHOIS database directly and that isn't
an easy and quick trick, generally.

2. Domain names check might be required to register that domain.
Again, gethostbyname(0 won't return anything useful.

3. In case the corresponding nameservers are unreachable at the
moment, gethostbyname() won't return anything valid

I only wished to say that gethostbyname() doesn't fit all the cases
and, in general, it makes validation significantly slower.

Best wishes,

Konstantin
This check will allow for a domain like 'foobar.quux.quuux.' even though
it is obviously not a real domain though. To check that it's a real,
registered domain name, which points to a real IP address, we can use
gethostbyname():

// Firstly, do all the above stuff to make sure it it syntactically
// correct. No point wasting network resources calling gethostbyname()
// for a domain that is obviously invalid. Now:

$domain_ok = $domain_ok && !empty(gethostbyname($domain));

// Now $domain_ok is TRUE iff $domain is an Internet host. Yay!

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~http://tobyinkster.co.uk/contact
Jan 28 '07 #6
Sagari wrote:
I only wished to say that gethostbyname() doesn't fit all the cases
and, in general, it makes validation significantly slower.
Please do not top post.

I did mention towards the end, that it actually checks if $domain is a
valid Internet host. Depending on why the OP needs to "validate" the
domain name this may or may not be important.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 28 '07 #7
Sam
When I do

$domainName = "google.com";
$res = ereg('#^(([a-z0-9][-a-z0-9]*?[a-z0-9])\.)+[a-z]{2,6}$#',
$domainName)

res was false :( and I got this warning

Warning: ereg() [function.ereg]: REG_BADRPT

Thanks

On Jan 28, 4:50 am, "Sagari" <konstan...@boyandin.ruwrote:
There's also '.museum' TLD, e.g.

example.museum

Non-national domain names can only have digits, Latin letters and a
dash in them; dash can't be first or last character. So you can begin
with this pattern:

#^(([a-z0-9][-a-z0-9]*?[a-z0-9])\.)+[a-z]{2,6}$#

That will match all valid 3-rd or higher level domain names as well

However, national domain names can have non-ASCII letters.

Best wishes,

Konstantin

On 28 ñÎ×., 02:12, "Sam" <m.shan...@gmail.comwrote:
yes sure
so any one have the pattren to check?
On Jan 27, 10:17 pm, bill <nob...@spamcop.netwrote:
Sam wrote:
Validate domain name context
Hello , Today I want to make sure from a given text is a domain style
or not.
for example : the domain can be
example.com or example.com.us or example.us so , what is the pattren
to check the given string is a domain style or not?
note that the first text must be at least 2 chars and the second text
may be 2 or 3 chars and the last text must be 2 chars or null.
Thanks,
Sam Shannaqcan also be example.info
bill- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Jan 28 '07 #8
..oO(Sam)
>When I do

$domainName = "google.com";
$res = ereg('#^(([a-z0-9][-a-z0-9]*?[a-z0-9])\.)+[a-z]{2,6}$#',
$domainName)

res was false :( and I got this warning

Warning: ereg() [function.ereg]: REG_BADRPT
Forget ereg*(), use the PCRE functions instead. They are much more
flexible and the preferred regex engine in PHP 6.

Micha
Jan 28 '07 #9
Sam wrote:
ereg('#^(([a-z0-9][-a-z0-9]*?[a-z0-9])\.)+[a-z]{2,6}$#',$domainName)
IIRC, the ereg() function doesn't expect any starting or ending characters
the the regular expression (the hash marks in the above).

Use preg_match() -- it's faster, more flexible and expects the starting and
ending characters!

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Jan 29 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: michaaal | last post by:
I realize this is not solely an ASP question, but I thought you guys might know the answer and I couldn't find anywhere else to post this. If you have suggestions for this I am more than happy to...
0
by: MG | last post by:
The following below is Microsoft sample to validate a XML document. My question is how can I put the validate errors in DataGrid? Using the ValidationEventHandle subroutine and adding ListBox...
12
by: Dag Sunde | last post by:
My understanding of regular expressions is rudimentary, at best. I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses...
2
by: Steffen Balslev | last post by:
I tried to find a way to validate user credentials using C#, searching google and lots of other news and kb sites left me without a solution. You can use a SSPI but it's that easy to implement so...
1
by: Raghuram | last post by:
if i want to validate the LDAP user like i will provide him with the domain name but not the user name and pass when the user enters the user name and pass i should validate towards my domain, and...
8
by: Jim in Arizona | last post by:
I was trying to have an email sent when the page loads but having some trouble with it. Our server is an IIS 6.0 with Framework 2.0. It is set to windows authentication (not anonymous). I...
23
by: codefire | last post by:
Hi, I am trying to get a regexp to validate email addresses but can't get it quite right. The problem is I can't quite find the regexp to deal with ignoring the case james..kirk@fred.com, which...
6
by: Solje | last post by:
Im developing an ASP.NET application used for maintinance purpose and it may be idle for some ours. The application crash with the error shown below when the user click on some contol in the...
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.