I have the following java script function in my perl document:
function emailcheck()
{
var emailoutline = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
var x = document.ec.email.value;
if (emailoutline.test(x))
{
alert("valid email");
}
}
that is part of a print html block so I think it should work fine. The html part works fine if I use it outside of the perl document, but once I link it there, it does not work anymore. The "@" in the regular expression is also marked green while all the rest of the html part of the script is marked red - I think the problem is that the "@" is interpreted by perl as the beginning of an array. Does anybody have an idea how to fix this problem?
This is the whole code:
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/html\n\n";
print <<'HTML';
<html>
<head>
<title>Mailcheck</title>
</head>
<body>
<form name="ec" action ="">
Email: <input type="text" name="email"> <br>
<input type="button" value="Pruefen" onclick="javascript:emailcheck();">
</form>
<script language="javascript" type="text/javascript">
function emailcheck()
{
var emailoutline = /^[a-z0-9._%+-]+\@[a-z0-9.-]+\.[a-z]{2,4}$/;
var x = document.ec.email.value;
if (emailoutline.test(x))
{
alert("This is a valid eMail");
}
else
{
alert("This is not a valid eMail");
}
}
</script>
</body>
HTML
exit;
\@
. In regex we can also express characters by its ascii code, you can also try using\x40
instead of@
(40 is the HEX equivalent to "@" in ascii table) – Caio Oliveira May 19 at 13:32