<html>
<head>
<title>Validation with JavaScript</title>
<script language="JavaScript">
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function isValid(parm,val) {
if (parm == "") return true;
if(parm.length>=25){
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}
return false;
}
function isAlpha(name)
{
if(isValid(name,lwr+upr) == false)
{document.getElementById("string").innerHTML = "name is not yet valid.";}
else
{document.getElementById("string").innerHTML = "You have entered a valid name!";}
}
function dob_validate(dob)
{
var regDob = /^([3][0-1]|[1-2][0-9]|[0][1-9]|[1-9])([.])([1][0-2]|[0][1-9]|[1-9])([.])([1][9][0-9][0-9]|[2][0][0][0-9]|[0-9][0-9])$/;
if(regDob.test(dob) == false)
{document.getElementById("status").innerHTML = "DOB is not yet valid.";}
else
{document.getElementById("status").innerHTML = "You have entered a valid DOB!";}}
</script>
<style type="text/css">
</style></head><body>
<div><form>
<span id="string">Please enter a valid name.</span><br>
<input type="text" name="name" onkeyup="isAlpha(this.value); ">
<br>
<span id="status">Please enter a valid date of birth.</span><br>
<input type="text" name="dob" onkeyup="dob_validate(this.value); ">
</form></div>
</body></html>
<head>
<title>Validation with JavaScript</title>
<script language="JavaScript">
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function isValid(parm,val) {
if (parm == "") return true;
if(parm.length>=25){
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}
return false;
}
function isAlpha(name)
{
if(isValid(name,lwr+upr) == false)
{document.getElementById("string").innerHTML = "name is not yet valid.";}
else
{document.getElementById("string").innerHTML = "You have entered a valid name!";}
}
function dob_validate(dob)
{
var regDob = /^([3][0-1]|[1-2][0-9]|[0][1-9]|[1-9])([.])([1][0-2]|[0][1-9]|[1-9])([.])([1][9][0-9][0-9]|[2][0][0][0-9]|[0-9][0-9])$/;
if(regDob.test(dob) == false)
{document.getElementById("status").innerHTML = "DOB is not yet valid.";}
else
{document.getElementById("status").innerHTML = "You have entered a valid DOB!";}}
</script>
<style type="text/css">
</style></head><body>
<div><form>
<span id="string">Please enter a valid name.</span><br>
<input type="text" name="name" onkeyup="isAlpha(this.value); ">
<br>
<span id="status">Please enter a valid date of birth.</span><br>
<input type="text" name="dob" onkeyup="dob_validate(this.value); ">
</form></div>
</body></html>
No comments:
Post a Comment