Java Reference
In-Depth Information
var pcodeRegExp = /^(\d{5}(-\d{4})?|
([a-z][a-z]?\d\d?|[a-z{2}\d[a-z]) ?\d[a-z][a-z])$/i
return pcodeRegExp.test( postalCode );
}
Again please remember that the regular expression must be on one line in your code.
Validating an E-mail Address
Before working on a regular expression to match e-mail addresses, you need to look at the types of valid
e-mail addresses you can have. For example:
someone@mailserver.com
someone@mailserver.info
someone.something@mailserver.com
someone.something@subdomain.mailserver.com
someone@mailserver.co.uk
someone@subdomain.mailserver.co.uk
someone.something@mailserver.co.uk
someone@mailserver.org.uk
some.one@subdomain.mailserver.org.uk
Also, if you examine the SMTP RFC ( http://www.ietf.org/rfc/rfc0821.txt ), you can have the
following:
someone@123.113.209.32
“”“Paul Wilton”“”@somedomain.com
That's quite a list and contains many variations to cope with. It's best to start by breaking it down. First,
there are a couple of things to note about the two immediately above. The latter two versions are excep-
tionally rate and not provided for in the regular expression you'll create.
You need to break up the e-mail address into separate parts, and you will look at the part after the @
symbol, fi rst.
Validating a Domain Name
Everything has become more complicated since Unicode domain names have been allowed. However,
the e-mail RFC still doesn't allow these, so let's stick with the traditional defi nition of how a domain can
be described using ASCII. A domain name consists of a dot-separated list of words, with the last word
being between two and four characters long. It was often the case that if a two-letter country word was
used, there would be at least two parts to the domain name before it: a grouping domain (.co, .ac,
and so on) and a specifi c domain name. However, with the advent of the .tv names, this is no longer
the case. You could make this very specifi c and provide for the allowed top-level domains (TLDs), but
that would make the regular expression very large, and it would be more productive to perform a DNS
lookup instead.
Search WWH ::




Custom Search