Java Reference
In-Depth Information
That was straightforward. Now for the domain name part:
^([^<>()\[\],;:@"\x00-\x20\x7F]|\\.)+@(([a-z]|#\d+?)([a-z0-9-]
|#\d+?)*([a-z0-9]|#\d+?)\.)+([a-z]{2,4})$
We've had to put it on two lines to it this topic's page width, but in your code this must all be on
one line.
Finally, here's the isValidEmail() function for reference:
function isValidEmail(emailAddress) {
var emailRegExp =
/^(([^<>()\[\]\\.,;:@"\x00-\x20\x7F]|\\.)+|("""([^\x0A\x0D"\\]|\\\\)+"""))
@(([a-z]|#\d+?)([a-z0-9-]|#\d+?)*([a-z0-9]|#\d+?)\.)
+([a-z]{2,4})$/i;
return emailRegExp.test( emailAddress );
}
Again, note the regular expression must all be on one line in your code.
summarY
In this chapter you've looked at some more advanced methods of the String object and how you
can optimize their use with regular expressions.
To recap, the chapter covered the following points:
The split() method splits a single string into an array of strings. You pass a string or a
regular expression to the method that determines where the split occurs.
The replace() method enables you to replace a pattern of characters with another pattern
that you specify as a second parameter.
The search() method returns the character position of the first pattern matching the one
given as a parameter.
The match() method matches patterns, returning the text of the matches in an array.
Regular expressions enable you to define a pattern of characters that you want to match.
Using this pattern, you can perform splits, searches, text replacement, and matches on
strings.
In JavaScript, the regular expressions are in the form of a RegExp object. You can
create a RegExp object using either myRegExp = /myRegularExpression/ or
myRegExp = new RegExp(“myRegularExpression”) . The second form requires that certain
special characters that normally have a single \ in front now have two.
The g and i characters at the end of a regular expression (as in, for example, myRegExp = /
Pattern/gi; ) ensure that a global and case‐insensitive match is made.
As well as specifying actual characters, regular expressions have certain groups of special
characters that allow any of certain groups of characters, such as digits, words, or non‐word
characters, to be matched.
 
Search WWH ::




Custom Search