HTML code:
<html>
<head>
<title>Registration</title>
<script src="val_registration.js" type="text/javascript"></script>
</head>
<body>
<form action="" method="post" id="myform">
<table>
<tr>
<td><label for="Last_name">Last name:<span id="imp">*</span></label></td><td><input type="text" id="Last_name" tabindex="5"/>
<br/><span class="eg"> eg:Le You</span></td></td>
</tr>
<tr>
<td><label for="E_mail">E-mail:<span id="imp">*</span></label></td>
<td><input type="text" id="E_mail" tabindex="10"/>
<br/><span class="eg"> eg:[email protected]</span></td></td>
</tr>
<tr>
<td colspan="4"><input type="submit" value="Confirm" id="confirm2" tabindex="11" onclick="val_registration ()"/>
<input type="reset" value="Cancel" id="cancel2" tabindex="12"/></td>
</tr>
</table>
</form>
</body>
</html>
JavaScript code:
function val_registration () {
var err = "";
var val_Last_name = document.getElementById("Last_name").value;
var string_Last_name = /^[a-zA-Z@'-_().,]{1,}$/;
if (val_Last_name == null || val_Last_name == "" || !string_Last_name.test(val_Last_name))
{
err += "\u2022Lastname cannot be blank/Lastname can contain\n alphabets or special symbols(@ ' - _ ( ).,) only.\n";
}
var val_E_mail = document.getElementById("E_mail").value;
var atpos = val_E_mail.indexOf("@");
var dotpos = val_E_mail.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2> = val_E_mail.length)
{
err += "\u2022E-mail cannot be blank/E-mail format must follow\n the example provided.\n";
}
alert(err);}
Based on the following codes, I would like to ask 3 questions:
First, why didn't the alert pop up??Is there anything wrong with my e-mail validation??
Second, why erroneous data such as <, >, /, * and etc can be entered into the last name field although I have this regular expression (/^[a-zA-Z@'-_().,]{1,}$/)? I just want the users to enter alphabetic data and the special symbols given in the regular expression above.Furthermore, I also found that the combination of both numeric and alphabetic data can be entered to this field also. Why did it happen?
Third, can I remove the border of input field? If this can be done, then how to do it?