[LON-CAPA-cvs] cvs: loncom /interface lonsupportreq.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Sat, 18 Dec 2004 22:30:28 -0000
raeburn Sat Dec 18 17:30:28 2004 EDT
Modified files:
/loncom/interface lonsupportreq.pm
Log:
More comprehensive checking of valid e-mail address if browser supports javascript regex.
Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.12 loncom/interface/lonsupportreq.pm:1.13
--- loncom/interface/lonsupportreq.pm:1.12 Sat Dec 18 17:21:52 2004
+++ loncom/interface/lonsupportreq.pm Sat Dec 18 17:30:28 2004
@@ -53,14 +53,35 @@
$usec = $ENV{'request.course.sec'};
$cid = $ENV{'request.course.id'};
$server = $ENV{'SERVER_NAME'};
- my $scripttag = (<<END);
+ my $scripttag = (<<'END');
function validate() {
- if (document.logproblem.email.value.indexOf("\@") == -1) {
- alert("You must enter a valid e-mail address");
- return
+ if (validmail(document.logproblem.email) == false) {
+ alert("The e-mail address you entered: "+document.logproblem.email.value+" is not a valid e-mail address.");
+ return;
}
document.logproblem.submit();
}
+
+function validmail(field) {
+ var str = field.value;
+ if (window.RegExp) {
+ var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
+ var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
+ var reg1 = new RegExp(reg1str);
+ var reg2 = new RegExp(reg2str);
+ if (!reg1.test(str) && reg2.test(str)) {
+ return true;
+ }
+ return false;
+ }
+ else
+ {
+ if(str.indexOf("@") >= 0) {
+ return true;
+ }
+ return false;
+ }
+}
END
if ($cid =~ m/_/) {
($cdom,$cnum) = split/_/,$cid;