SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 210 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

php file is a very basic example of how you might do regexp-based validation
in PHP on the server. Each field is given a regexp to match against what the user
submits and an error message to display if it doesn??™t match. For example, the ???number of
heads??? field must contain digits, so its regexp is ^\d+$. (Note the +, meaning ???one or more of
these,??? which makes this field compulsory.) If completing the field were optional (so it could
be left blank), the regexp would have been ^\d*$ because * means ???zero or more of these.???
Note also that some of these regexps are fairly simplistic. Regular expressions are good
but imperfect tools. For example, the e-mail regexp??”^.+@.+\..+$??”allows invalid nastinesses
such as stuart@somewhere@somewhere@somewhere.com. You often cannot completely rely on
a regexp to give you validity. http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html has
CHAPTER 7 n FORM VALIDATION AND JAVASCRIPT 149
a ???proper??? regexp for matching e-mail addresses, which is a mighty 6251 characters long.
In practice, what you??™re doing with validation here is stripping out things that are obviously
wrong, not trying to catch every single invalid case.
The Client Side
On to JavaScript. JavaScript supports regexps natively; a string has a search() method that
takes a regexp as parameter and returns the first character where the regexp is found in the
string, or -1 if it??™s not found at all.


Pages:
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6