XerX 0 Newbie Poster

Hello. I have trouble with detecting a letter in a text box where there should be only digits and vice-versa. This is my program:

<html>
<head>
<script type="text/javascript">

test1=/[0-9]/i;
test2=/[A-z]/i;

function check()
{
var i=false;
if (!test2.test(document.getElementById("name").value))
	{
	alert("wrong name");
	i=true;
	}
if (document.getElementById("card").value.length > 16)
	{
	alert("too long card number");
	i=true;
	}
if (!test1.test(document.getElementById("expireM").value))
	{
	alert("You have entered letters for month");
	i=true;
	}
if (!test1.test(document.getElementById("expireY").value))
	{
	alert("You have entered letters for year");
	i=true;
	}
if (document.getElementById("expireM").value>12 || document.getElementById("expireM").value<1)
	{
	alert("Wrong month");
	i=true;
	}
if (document.getElementById("expireY").value<2011)
	{
	alert("Your card has expired");
	i=true;
	}
if (i==false)
	{
	var a=prompt("Enter your EGN:");
	var sex=prompt("Enter your sex:");
	var day=prompt("Enter the day you were born:");
	var month=prompt("Enter the month you were born:");
	var year=prompt("Enter the year you were born:");
	var a2=a.toString();
	if (a2.substr(0,2)!=year || a2.substr(2,2)!=month || a2.substr(4,2)!=day)
		{
		alert("Wrong EGN");
		}
	if (a2.substr(8,9)%2!=0 && sex=="m")
		{
		alert("Wrong EGN or sex");
		}
	if (a2.substr(8,9)%2==0 && sex=="f")
		{
		alert("Wrong EGN or sex");
		}
	var last=a2.substr(0,1)*2+a2.substr(1,2)*4+a2.substr(2,3)*8+a2.substr(3,4)*5+a2.substr(4,5)*10+a2.substr(5,6)*9+a2.substr(6,7)*7+a2.substr(7,8)*3+a2.substr(8,9)*6;
	if (last%11<10 && last%11!=a2.substr(9))	
		{
		alert("Wrong last digit of EGN");
		}
	if (last%11>10 && last%11!=0)
		{
		alert("Wrong last digit of EGN");
		}
	}
}
</script>
</head>
<body>
<form>
Name: <input type="text" id="name" size="30"><br />
Card number: <input type="text" id="card" size="30"><br />
Card Expiry Date: <input type="text" id="expireM" size="3">/<input type="text" id="expireY" size="3"><br />
<input type="button" value="Check" onclick=check()>
</form>
</body>
</html>

For Name field I have to make sure that there is at least 1 character. For card number field I have to check if all are digits. How do I do these two? Please, help. Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.