Chapter 16 Answers
You can send a form for validation prior to submitting it by adding the JavaScript
onSubmitmethod to the<form>tag. Make sure that your function returnstrueif the form is to be submitted andfalseotherwise.To match a string against a regular expression in JavaScript, use the
testmethod.Regular expressions to match characters not in a word could be any of
/[^\w]/,/[\W]/,/[^a-zA-Z0-9_]/, and so on.A regular expression to match either of the words “fox” or “fix” could be
/f[oi]x/.A regular expression to match any single word followed by any nonword character could be
/\w+\W/g.A JavaScript function using regular expressions to test whether the word “fox” exists in the string “The quick brown fox” could be:
document.write(/fox/.test("The quick brown fox"))A PHP function using a regular expression to replace all occurrences of the word “the” in “The cow jumps over the moon” with the word “my” could be:
$s=preg_replace("/the/i", "my", "The cow jumps over the moon");The HTML keyword used to precomplete form fields with a value is the
valuekeyword, which is placed within an<input>tag and takes the formvalue="value".
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access