[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm lonsupportreq.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 07 May 2007 14:02:45 -0000
raeburn Mon May 7 10:02:45 2007 EDT
Modified files:
/loncom/interface lonsupportreq.pm lonhtmlcommon.pm
Log:
Making javascript used to validate e-mail addresses more widely available.
Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.42 loncom/interface/lonsupportreq.pm:1.43
--- loncom/interface/lonsupportreq.pm:1.42 Fri Dec 22 15:51:27 2006
+++ loncom/interface/lonsupportreq.pm Mon May 7 10:02:45 2007
@@ -1,5 +1,5 @@
#
-# $Id: lonsupportreq.pm,v 1.42 2006/12/22 20:51:27 albertel Exp $
+# $Id: lonsupportreq.pm,v 1.43 2007/05/07 14:02:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -32,6 +32,7 @@
use CGI::Cookie();
use Apache::Constants qw(:common);
use Apache::loncommon();
+use Apache::lonhtmlcommon;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::lonacc();
@@ -138,29 +139,7 @@
}
END
- $scripttag .= <<'END';
-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
-
+ $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
if ($cid =~ m/_/) {
($cdom,$cnum) = split(/_/,$cid);
}
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.157 loncom/interface/lonhtmlcommon.pm:1.158
--- loncom/interface/lonhtmlcommon.pm:1.157 Mon Mar 12 14:09:36 2007
+++ loncom/interface/lonhtmlcommon.pm Mon May 7 10:02:45 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.157 2007/03/12 18:09:36 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.158 2007/05/07 14:02:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1841,6 +1841,43 @@
return $output;
}
+##############################################
+##############################################
+
+# javascript_valid_email
+#
+# Generates javascript to validate an e-mail address.
+# Returns a javascript function which accetps a form field as argumnent, and
+# returns false if field.value does not satisfy two regular expression matches
+# for a valid e-mail address. Backwards compatible with old browsers without
+# support for javascript RegExp (just checks for @ in field.value in this case).
+
+sub javascript_valid_email {
+ my $scripttag .= <<'END';
+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
+ return $scripttag;
+}
+
1;
__END__