Get it? “Reg ex”!!! Okay, maybe you didn’t take Latin in school.
Now that I have your attention…
I’ve read about regex (I purchased “Teach Yourself Regular Expressions in 10 Minutes”, by Ben Forta) and understand what they’re for and why they’re used, but still can’t see the need and what it does in the following javascript (which I copied from another page on this site). It’s a form:
[QUOTE]
function valid(form) {
var field = form.email;
var str = field.value;
if (window.RegExp) {
var reg1str = “(@.*@)|(^
var reg2str = “^.+
var reg1 = new RegExp(reg1str);
var reg2 = new RegExp(reg2str);
if (!reg1.test(str) && reg2.test(str))
return true;
field.focus();
field.select();
return false;
} else {
if(str.indexOf(“@”) >= 0)
return true;
field.focus();
field.select();
return false;
}
}
</SCRIPT>
<FORM METHOD=”POST”
ACTION=”mailto:
ENCTYPE=”text/plain”
onSubmit=”return valid(this)”>
Your e-mail address:<BR><INPUT TYPE=”text” NAME=”email” SIZE=”40″><BR>
Subject:<BR><INPUT TYPE=”text” NAME=”subject” SIZE=”40″><BR>
Comments:<BR><TEXTAREA NAME=”comments” COLS=”40″ ROWS=”5″></TEXTAREA><BR>
<INPUT TYPE=”submit” VALUE=”Send Mail”>
</FORM>
Also, the book actually leaves out two very important points… ie – where one writes the regex, and how regex highlights the soughtafter text once it does it’s thing.
Any help?
Thanks.